Skip to content
Browse files

Merge pull request #11 from gibletto/master

Added native Function.prototype.bind rendition
  • Loading branch information...
2 parents b5f1134 + 40ba75e commit 6115d88a7148831af2ee9ed3248887db74fe4565 @david-mark david-mark committed
Showing with 30 additions and 0 deletions.
  1. +7 −0 functions/bind/rendition2.js
  2. +23 −0 functions/bind/rendition3.js
View
7 functions/bind/rendition2.js
@@ -0,0 +1,7 @@
+var bind;
+
+if(Function.prototype.bind){
+ bind = function(fn, thisObject) {
+ return fn.bind.apply(fn, Array.prototype.slice.call(arguments, 1));
+ };
+}
View
23 functions/bind/rendition3.js
@@ -0,0 +1,23 @@
+
+var bind;
+if(Function.prototype.bind){
+ bind = function(fn, thisObject) {
+ return fn.bind.apply(fn, Array.prototype.slice.call(arguments, 1));
+ };
+}
+else {
+ if(canCall) {
+ 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);
+ };
+ };
+ }
+}

0 comments on commit 6115d88

Please sign in to comment.
Something went wrong with that request. Please try again.