// bind if ( !Function.prototype.bind ){ Function.prototype.bind = function(context){ if ( typeof this !== 'function' ){ console.log('this is not function'); throw new Error('this is not function'); return ; }
var args = Array.prototype.slice.call(arguments, 1), self = this; var tmpFunc = function(){}; // 构造函数原型链继承 var mainFunc = function(){ var innerArgs = Array.prototype.slice.call(arguments); //改变上下文之后的arguments var finalArgs = args.concat(innerArgs); return self.apply(this instanceof tmpFunc ? this : context || window,finalArgs); };