From 974cbb6b1b553930422d8de28c269e3cc1832823 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 31 Jan 2014 11:36:02 -0500 Subject: [PATCH] fix(polyfill) bind --- lib/client/polyfill.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/client/polyfill.js b/lib/client/polyfill.js index f19949a9..9807043a 100644 --- a/lib/client/polyfill.js +++ b/lib/client/polyfill.js @@ -30,13 +30,22 @@ var Util, DOM, jQuery; } if (!Function.bind) - Function.prototype.bind = function(context) { - var _this = this; + Function.prototype.bind = function (context) { + var aArgs = Util.slice(arguments, 1), + fToBind = this, + NOP = function () {}, + fBound = function () { + var arr = Util.slice(arguments); + args = aArgs.concat(arr); + + return fToBind.apply(context, args); + }; + + NOP.prototype = this.prototype; + fBound.prototype = new NOP(); - return function() { - return _this.apply(context, arguments); - }; - }; + return fBound; + }; /* * typeof callback === "function" should not be used,