手写call,apply方法实现
程序员文章站
2022-04-12 09:39:33
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; }
上一篇: 安装Win10,ERROR_0x8007025D问题解决
下一篇: mysql 写入中文乱码