Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Do not call getElements on a script tag. Avoids unnecessary execution…
…. Fixes #10176.
- Loading branch information
Showing
2 changed files
with
14 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use
!== undefined
instead oftypeof .. !== "undefined"
? Afaik 'undefined' can be safely used in a strict comparison within jQuery context since it's explicitly made undefined in the closure. Using a strict reference comparison gives faster performance (and it's shorter in code/bandwidth) than executing the typeof operator and doing a string comparison on the result.3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing as an argument to typeof avoids the arbitrary execution of the given function in IE and has the added bonus of being noticeably faster than using the
in
operator. Using typeof vs. solely checking for property existence does not actually differ in performance enough to be a concern, according to what we've seen. http://jsperf.com/in-vs-typeof3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't suggesting to use the
in
operator... suggesting to use strict comparison to theundefined
reference instead of the string "undefined" returned by thetypeof
operator. As done in other parts of jQuery core, like here3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Krinkle, using strict comparison causes the function to be executed in IE... thus causing side effects. The fact that certain other parts of jQuery core may or may not conform to such standards (although the line you pointed do isn't an example of inconsistency in this case, it just looks like one) isn't really a good argument.
The three options are:
3 is the clear winner here.
3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I didn't think there'd that much of a difference in how IE treats the object member access between
if ( foo.bar !== undefined )
andif ( typeof foo.bar !== 'undefined' )
. Anyway, I agree option 3 makes perfect sense here. Thanks3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mike. You said it better.
3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikesherov this was interesting. I am looking for sources that support this (yes I have trid google it). You know for which versions of IE this is true? You got any method checking this? Is this true only for built in native methods? Cause I couldn´t reproduce it with userland code.
3ad0ba6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anddoutoi: http://jsfiddle.net/timmywil/NzUKW/ A situation where the method call throws an error.