Version 1
[yaffs-website] / node_modules / core-js / modules / _bind.js
1 'use strict';
2 var aFunction  = require('./_a-function')
3   , isObject   = require('./_is-object')
4   , invoke     = require('./_invoke')
5   , arraySlice = [].slice
6   , factories  = {};
7
8 var construct = function(F, len, args){
9   if(!(len in factories)){
10     for(var n = [], i = 0; i < len; i++)n[i] = 'a[' + i + ']';
11     factories[len] = Function('F,a', 'return new F(' + n.join(',') + ')');
12   } return factories[len](F, args);
13 };
14
15 module.exports = Function.bind || function bind(that /*, args... */){
16   var fn       = aFunction(this)
17     , partArgs = arraySlice.call(arguments, 1);
18   var bound = function(/* args... */){
19     var args = partArgs.concat(arraySlice.call(arguments));
20     return this instanceof bound ? construct(fn, args.length, args) : invoke(fn, args, that);
21   };
22   if(isObject(fn.prototype))bound.prototype = fn.prototype;
23   return bound;
24 };