手写call,apply方法实现
程序员文章站
2022-08-17 16:23:19
call apply ......
call
function.prototype.mycall = function(){ var object = arguments[0]; var arr = []; for(var i = 1; i < arguments.length; i++){ arr.push(arguments[i]); } object.__proto__._fn = this; var result = object._fn(...arr); delete object.__proto__._fn; return result; }
apply
function.prototype.myapply = function(object,arr){ object.__proto__._fn = this; var result = object._fn(...arr); delete object.__proto__._fn; return result; }
下一篇: 男人爱你时会叫你增重