如何实现myBind函数能够使testB的结果为3;
var testA = function (b) {
return this.a + b;
};
var obj = {a: 2};
var testB = testA.myBind(obj, 1);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
es5 写法
Function.prototype.myBind = function(){var arg1 = Array.prototype.shift.call(arguments); return this.call(arg1, arguments)}这不就是Function.prototype.bind的实现么~~