You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					26 lines
				
				903 B
			
		
		
			
		
	
	
					26 lines
				
				903 B
			| 
								 
											3 years ago
										 
									 | 
							
								'use strict';
							 | 
						||
| 
								 | 
							
								var aFunction = require('./_a-function');
							 | 
						||
| 
								 | 
							
								var isObject = require('./_is-object');
							 | 
						||
| 
								 | 
							
								var invoke = require('./_invoke');
							 | 
						||
| 
								 | 
							
								var arraySlice = [].slice;
							 | 
						||
| 
								 | 
							
								var factories = {};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								var construct = function (F, len, args) {
							 | 
						||
| 
								 | 
							
								  if (!(len in factories)) {
							 | 
						||
| 
								 | 
							
								    for (var n = [], i = 0; i < len; i++) n[i] = 'a[' + i + ']';
							 | 
						||
| 
								 | 
							
								    // eslint-disable-next-line no-new-func
							 | 
						||
| 
								 | 
							
								    factories[len] = Function('F,a', 'return new F(' + n.join(',') + ')');
							 | 
						||
| 
								 | 
							
								  } return factories[len](F, args);
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = Function.bind || function bind(that /* , ...args */) {
							 | 
						||
| 
								 | 
							
								  var fn = aFunction(this);
							 | 
						||
| 
								 | 
							
								  var partArgs = arraySlice.call(arguments, 1);
							 | 
						||
| 
								 | 
							
								  var bound = function (/* args... */) {
							 | 
						||
| 
								 | 
							
								    var args = partArgs.concat(arraySlice.call(arguments));
							 | 
						||
| 
								 | 
							
								    return this instanceof bound ? construct(fn, args.length, args) : invoke(fn, args, that);
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								  if (isObject(fn.prototype)) bound.prototype = fn.prototype;
							 | 
						||
| 
								 | 
							
								  return bound;
							 | 
						||
| 
								 | 
							
								};
							 |