We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ECMAScript 中的 apply() 方法使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数。 下面我们编写一个函数 myapply 来模拟 apply 方法,以此加深对 apply 的理解。
apply()
myapply
apply
相关:第 52 期(W3C 标准-ECMAScript-上下文环境):模拟call方法
Function.prototype.myApply = function(context, arr) { context = context || window; context.fn = this; var result; if (!arr) { result = context.fn(); } else { var args = []; for (var i = 0; i < arr.length; i++) { args.push('arr[' + i + ']'); } result = eval('context.fn(' + args + ')'); } delete context.fn; return result; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
ECMAScript 中的
apply()
方法使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数。下面我们编写一个函数
myapply
来模拟apply
方法,以此加深对apply
的理解。The text was updated successfully, but these errors were encountered: