{"aliases":["default","es5","modernizr:es5function","blissfuljs"],"browsers":{"ie":"6 - 8","firefox":"3.6","safari":"4 - 5.1","ios_saf":"<=5","firefox_mob":"3.6"},"dependencies":["Object.defineProperty"],"repo":"https://github.com/es-shims/es5-shim","license":"MIT","docs":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind","spec":"http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.bind","baseDir":"Function/prototype/bind","hasTests":true,"rawSource":"\n// Function.prototype.bind\n// https://github.com/es-shims/es5-shim/blob/d6d7ff1b131c7ba14c798cafc598bb6780d37d3b/es5-shim.js#L182\nObject.defineProperty(Function.prototype, 'bind', {\n    value: function bind(that) { // .length is 1\n        // add necessary es5-shim utilities\n        var $Array = Array;\n        var $Object = Object;\n        var ObjectPrototype = $Object.prototype;\n        var ArrayPrototype = $Array.prototype;\n        var Empty = function Empty() {};\n        var to_string = ObjectPrototype.toString;\n        var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';\n        var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };\n        var array_slice = ArrayPrototype.slice;\n        var array_concat = ArrayPrototype.concat;\n        var array_push = ArrayPrototype.push;\n        var max = Math.max;\n        // /add necessary es5-shim utilities\n\n        // 1. Let Target be the this value.\n        var target = this;\n        // 2. If IsCallable(Target) is false, throw a TypeError exception.\n        if (!isCallable(target)) {\n            throw new TypeError('Function.prototype.bind called on incompatible ' + target);\n        }\n        // 3. Let A be a new (possibly empty) internal list of all of the\n        //   argument values provided after thisArg (arg1, arg2 etc), in order.\n        // XXX slicedArgs will stand in for \"A\" if used\n        var args = array_slice.call(arguments, 1); // for normal call\n        // 4. Let F be a new native ECMAScript object.\n        // 11. Set the [[Prototype]] internal property of F to the standard\n        //   built-in Function prototype object as specified in 15.3.3.1.\n        // 12. Set the [[Call]] internal property of F as described in\n        //   15.3.4.5.1.\n        // 13. Set the [[Construct]] internal property of F as described in\n        //   15.3.4.5.2.\n        // 14. Set the [[HasInstance]] internal property of F as described in\n        //   15.3.4.5.3.\n        var bound;\n        var binder = function () {\n\n            if (this instanceof bound) {\n                // 15.3.4.5.2 [[Construct]]\n                // When the [[Construct]] internal method of a function object,\n                // F that was created using the bind function is called with a\n                // list of arguments ExtraArgs, the following steps are taken:\n                // 1. Let target be the value of F's [[TargetFunction]]\n                //   internal property.\n                // 2. If target has no [[Construct]] internal method, a\n                //   TypeError exception is thrown.\n                // 3. Let boundArgs be the value of F's [[BoundArgs]] internal\n                //   property.\n                // 4. Let args be a new list containing the same values as the\n                //   list boundArgs in the same order followed by the same\n                //   values as the list ExtraArgs in the same order.\n                // 5. Return the result of calling the [[Construct]] internal\n                //   method of target providing args as the arguments.\n\n                var result = target.apply(\n                    this,\n                    array_concat.call(args, array_slice.call(arguments))\n                );\n                if ($Object(result) === result) {\n                    return result;\n                }\n                return this;\n\n            } else {\n                // 15.3.4.5.1 [[Call]]\n                // When the [[Call]] internal method of a function object, F,\n                // which was created using the bind function is called with a\n                // this value and a list of arguments ExtraArgs, the following\n                // steps are taken:\n                // 1. Let boundArgs be the value of F's [[BoundArgs]] internal\n                //   property.\n                // 2. Let boundThis be the value of F's [[BoundThis]] internal\n                //   property.\n                // 3. Let target be the value of F's [[TargetFunction]] internal\n                //   property.\n                // 4. Let args be a new list containing the same values as the\n                //   list boundArgs in the same order followed by the same\n                //   values as the list ExtraArgs in the same order.\n                // 5. Return the result of calling the [[Call]] internal method\n                //   of target providing boundThis as the this value and\n                //   providing args as the arguments.\n\n                // equiv: target.call(this, ...boundArgs, ...args)\n                return target.apply(\n                    that,\n                    array_concat.call(args, array_slice.call(arguments))\n                );\n\n            }\n\n        };\n\n        // 15. If the [[Class]] internal property of Target is \"Function\", then\n        //     a. Let L be the length property of Target minus the length of A.\n        //     b. Set the length own property of F to either 0 or L, whichever is\n        //       larger.\n        // 16. Else set the length own property of F to 0.\n\n        var boundLength = max(0, target.length - args.length);\n\n        // 17. Set the attributes of the length own property of F to the values\n        //   specified in 15.3.5.1.\n        var boundArgs = [];\n        for (var i = 0; i < boundLength; i++) {\n            array_push.call(boundArgs, '$' + i);\n        }\n\n        // XXX Build a dynamic function with desired amount of arguments is the only\n        // way to set the length property of a function.\n        // In environments where Content Security Policies enabled (Chrome extensions,\n        // for ex.) all use of eval or Function costructor throws an exception.\n        // However in all of these environments Function.prototype.bind exists\n        // and so this code will never be executed.\n        bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);\n\n        if (target.prototype) {\n            Empty.prototype = target.prototype;\n            bound.prototype = new Empty();\n            // Clean up dangling references.\n            Empty.prototype = null;\n        }\n\n        // TODO\n        // 18. Set the [[Extensible]] internal property of F to true.\n\n        // TODO\n        // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).\n        // 20. Call the [[DefineOwnProperty]] internal method of F with\n        //   arguments \"caller\", PropertyDescriptor {[[Get]]: thrower, [[Set]]:\n        //   thrower, [[Enumerable]]: false, [[Configurable]]: false}, and\n        //   false.\n        // 21. Call the [[DefineOwnProperty]] internal method of F with\n        //   arguments \"arguments\", PropertyDescriptor {[[Get]]: thrower,\n        //   [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},\n        //   and false.\n\n        // TODO\n        // NOTE Function objects created using Function.prototype.bind do not\n        // have a prototype property or the [[Code]], [[FormalParameters]], and\n        // [[Scope]] internal properties.\n        // XXX can't delete prototype in pure-js.\n\n        // 22. Return F.\n        return bound;\n    }\n});\n","minSource":"Object.defineProperty(Function.prototype,\"bind\",{value:function(t){var n,o=Array,r=Object,e=r.prototype,i=o.prototype,c=function(){},p=e.toString,l=\"function\"==typeof Symbol&&\"symbol\"==typeof Symbol.toStringTag,a=Function.prototype.toString,u=function(t){try{return a.call(t),!0}catch(n){return!1}},y=\"[object Function]\",f=\"[object GeneratorFunction]\";n=function(t){if(\"function\"!=typeof t)return!1;if(l)return u(t);var n=p.call(t);return n===y||n===f};var b=i.slice,h=i.concat,s=i.push,g=Math.max,d=this;if(!n(d))throw new TypeError(\"Function.prototype.bind called on incompatible \"+d);for(var m,v=b.call(arguments,1),F=function(){if(this instanceof m){var n=d.apply(this,h.call(v,b.call(arguments)));return r(n)===n?n:this}return d.apply(t,h.call(v,b.call(arguments)))},j=g(0,d.length-v.length),S=[],w=0;j>w;w++)s.call(S,\"$\"+w);return m=Function(\"binder\",\"return function (\"+S.join(\",\")+\"){ return binder.apply(this, arguments); }\")(F),d.prototype&&(c.prototype=d.prototype,m.prototype=new c,c.prototype=null),m}});","detectSource":"'bind' in Function.prototype"}