Skip to content

Commit

Permalink
Implement Function.prototype.bind in functionBind.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fay-jai committed Dec 31, 2014
1 parent ac691ad commit 277f5e8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions functionBind/functionBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
var bind = function (fn, context) {
var outerArgs = Array.prototype.slice.call(arguments, 2);
return function () {
var totalArgs = Array.prototype.concat( outerArgs, Array.prototype.slice.call(arguments) );
var innerArgs = Array.prototype.slice.call(arguments);
var totalArgs = Array.prototype.concat( outerArgs, innerArgs );
return fn.apply(context, totalArgs);
};
};
Expand Down Expand Up @@ -56,6 +57,12 @@ var bind = function (fn, context) {
*
*/

Function.prototype.bind = function () {
// TODO: Your code here
Function.prototype.bind = function (context) {
var fn = this; // function object
var outerArgs = Array.prototype.slice.call(arguments, 1);
return function () {
var innerArgs = Array.prototype.slice.call(arguments);
var totalArgs = Array.prototype.concat( outerArgs, innerArgs );
return fn.apply( context, totalArgs );
};
};

0 comments on commit 277f5e8

Please sign in to comment.