🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@markraddatz
Copy link
Contributor

This will fix .replaceWith() when you pass an empty string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not elem === "" instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test also handles the case of " ", which wouldn't work with elem === ""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but would have been caught by elem since !!" " === true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elem === "" should work as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-3 bytes by changing this condition to elem != null && elem !== false.

@gibson042
Copy link
Member

I approve of this pull, but it changes the behavior of other manipulation methods (append/prepend/before/after and *To/insert* inversions) and thus may not be fit for a patch release. But there is a regression with respect to 1.8 replaceWith, so maybe we should special-case "" or something (I'm open to suggestion on that).

@markraddatz
Copy link
Contributor Author

From this perspective I totally agree that the change causes more harm than good. I prefer to have a lean childNodes list without clutters of empty strings. I opt in for a solution that uses the 1.8 replaceWith way without domManip.

@gibson042
Copy link
Member

@markraddatz Do you want to submit another pull request with that approach? I'd suggest keeping the .domManip dependency but just adding a value === "" check in .replaceWith that either redefines value or (probably better) skips .domManip in favor of .remove.

@markraddatz
Copy link
Contributor Author

I submitted a new pull request that skips .domManip for this special case.

@dmethvin
Copy link
Member

dmethvin commented Feb 7, 2013

Closing in favor of gh-1163.

@dmethvin dmethvin closed this Feb 7, 2013
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants