Reflect.apply()
Reflect.apply() 静态方法使用指定的参数调用目标函数。
¥The Reflect.apply() static method calls a target function with arguments as specified.
Try it
语法
参数
¥Parameters
target-
要调用的目标函数。
thisArgument-
为调用
target提供的this值。 argumentsList-
类似数组的对象 指定应调用
target的参数。
返回值
例外情况
描述
¥Description
Reflect.apply() 提供函数调用的反射语义。也就是说,Reflect.apply(target, thisArgument, argumentsList) 在语义上等同于:
¥Reflect.apply() provides the reflective semantic of a function call. That is, Reflect.apply(target, thisArgument, argumentsList) is semantically equivalent to:
js
Math.floor.apply(null, [1.75]);
Reflect.apply(Math.floor, null, [1.75]);
唯一的区别是:
¥The only differences are:
Reflect.apply()将要调用的函数作为target参数而不是this上下文。- 如果省略
argumentsList,则Reflect.apply()会抛出异常,而不是默认不带参数调用。
Reflect.apply() 调用 target 的 [[Call]] 对象内部方法。
¥Reflect.apply() invokes the [[Call]] object internal method of target.
示例
使用 Reflect.apply()
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-reflect.apply |
浏览器兼容性
BCD tables only load in the browser