-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2004 - Fix Function:bind when the resulting function is used a…
…s constructor
- Loading branch information
Showing
1 changed file
with
15 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,15 +38,23 @@ Function.implement({ | |
}, | ||
|
||
/*<!ES5>*/ | ||
bind: function(bind){ | ||
bind: function(that){ | ||
var self = this, | ||
args = (arguments.length > 1) ? Array.slice(arguments, 1) : null; | ||
|
||
return function(){ | ||
if (!args && !arguments.length) return self.call(bind); | ||
if (args && arguments.length) return self.apply(bind, args.concat(Array.from(arguments))); | ||
return self.apply(bind, args || arguments); | ||
args = arguments.length > 1 ? Array.slice(arguments, 1) : null, | ||
F = function(){}; | ||
|
||
var bound = function(){ | ||
var context = that, length = arguments.length; | ||
if (this instanceof bound){ | ||
F.prototype = self.prototype; | ||
context = new F; | ||
} | ||
var result = (!args && !length) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
? self.call(context) | ||
: self.apply(context, args && length ? args.concat(Array.slice(arguments)) : args || arguments); | ||
return context == that ? result : context; | ||
}; | ||
This comment has been minimized.
Sorry, something went wrong.
jdalton
|
||
return bound; | ||
}, | ||
/*</!ES5>*/ | ||
|
||
|
when
this instanceof bound
the return should allow for the constructor returning a custom object