Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ var root = typeof self == 'object' && self.self === self && self ||
{};

// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
var ArrayProto = Array.prototype, FuncProto = Function.prototype, ObjProto = Object.prototype;
var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;

// Create quick reference variables for speed access to core prototypes.
var push = ArrayProto.push,
slice = ArrayProto.slice,
_bind = FuncProto.bind,
toString = ObjProto.toString,
hasOwnProperty = ObjProto.hasOwnProperty;

Expand Down Expand Up @@ -766,7 +767,9 @@ function executeBound(sourceFunc, boundFunc, context, callingContext, args) {
// Create a function bound to a given object (assigning `this`, and arguments,
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
// available.
export var bind = restArguments(function(func, context, args) {
export var bind = _bind ? restArguments(function(func, args) {
return _bind.apply(func, args);
}) : restArguments(function(func, context, args) {
if (!isFunction(func)) throw new TypeError('Bind must be called on a function');
var bound = restArguments(function(callArgs) {
return executeBound(func, bound, context, this, args.concat(callArgs));
Expand Down
6 changes: 6 additions & 0 deletions test/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
assert.strictEqual(boundf().hello, 'moe curly', "When called without the new operator, it's OK to be bound to the context");
assert.ok(newBoundf instanceof F, 'a bound instance is an instance of the original function');

// Ensure that we are not reproducing #2214.
var D = _.bind(Date, null, 2015, 5);
var newD = new D(10);
assert.ok(newD instanceof Date, 'works on variable argument constructors');
assert.ok(newD.toISOString(), 'works on nontrivial constructors');

assert.raises(function() { _.bind('notafunction'); }, TypeError, 'throws an error when binding to a non-function');
});

Expand Down
7 changes: 5 additions & 2 deletions underscore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore.js.map

Large diffs are not rendered by default.