-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Reimplement removed constructor naming #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,6 @@ this.util = this.util || {}; | |
| * @throws {Error} if the given name has no characters matching [\w$]. | ||
| */ | ||
| function createNamedFunction( name, originalFn ) { | ||
| /* jshint evil: true */ | ||
| /* jshint unused: false */ | ||
| var namedFn; | ||
| var evilsSeed = originalFn || EMPTY_FN; | ||
| var fnName = name.replace( /(?:(^\d+)|[^\w$])/ig, '' ); | ||
|
|
@@ -52,10 +50,13 @@ this.util = this.util || {}; | |
| throw new Error( 'Bad function name given. At least one word character or $ required.' ); | ||
| } | ||
|
|
||
| eval( 'namedFn = function ' + fnName + | ||
| '(){ evilsSeed.apply( this, arguments ); }' ); | ||
| // No, none of these functions is superfluous! Before this used to fail with a | ||
| // "ReferenceError: evilsSeed is not defined" when Shift+reloading in Firefox. | ||
| // Source: http://stackoverflow.com/a/22880379 | ||
| namedFn = ( new Function( 'return function( fn ) { return function ' + fnName + | ||
| '() { return fn( this, arguments ); }; };' )() )( Function.apply.bind( evilsSeed ) ); | ||
|
|
||
| return namedFn; // value got assigned in eval | ||
| return namedFn || evilsSeed; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you change this? namedFn should always == true
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be sure. It may be superfluous but it doesn't hurt.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous code can be very misleading |
||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
How about
?
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.
Yay for the
'fn'bit. Need to test this but looks good. Nay for the droppedbind. I think this is crucial.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.
Why is it crucial?
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.
It was when I played around with my version. Since this is hard/impossible to test I'm afraid to change my version (the only one that works for sure, as far as I know) to something else.