Function.prototype.testBind = function(that) {
var _this = this
var args = Array.prototype.slice.apply(arguments, [1])
return function (){
return _this.apply(that, args.concat(Array.prototype.slice(arguments, [0])))
}
}
var testObj = function(a, b) {
console.log('作用域绑定 '+ this.value)
console.log('testBind参数传递 '+ a.value2)
console.log('调用参数传递 ' + b)
}
var obj = {
value: '作用域'
}
var func = testObj.bind(obj, {value2: 'a'})
func('fasd')
Function.prototype.mybind = function(){
var _this = this;
var context = arguments[0]||window;
var rest = Array.prototype.slice.call(arguments,1);
return function F(){
var rest2 = Array.prototype.slice.call(arguments)
_this.apply(context,rest.concat(rest2));
}
}
Function.prototype.myBind = function(ctx, ...argv1) {
return (...argv2) => {
return this.call(ctx, ...argv1, ...argv2)
}
}
console