Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a rendition 3 for the bind method
- Loading branch information
Ian Crowther
committed
Aug 1, 2012
1 parent
b406610
commit 1628fcd
Showing
1 changed file
with
27 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*global canCall */ | ||
|
||
/* | ||
Description: | ||
Both W3C and MS implementation therefore providing the greatest browser support | ||
*/ | ||
|
||
var bind; | ||
|
||
if(canCall && Function.prototype.bind){ | ||
bind = function(fn, thisObject) { | ||
return fn.bind.apply(fn, Array.prototype.slice.call(arguments, 1)); | ||
}; | ||
} else if(canCall && Array.prototype.slice) { | ||
bind = function(fn, context) { | ||
var prependArgs = Array.prototype.slice.call(arguments, 2); | ||
|
||
if (prependArgs.length) { | ||
return function() { | ||
fn.apply(context, Array.prototype.concat.apply(prependArgs, arguments)); | ||
}; | ||
} | ||
return function() { | ||
fn.apply(context, arguments); | ||
}; | ||
}; | ||
} |