首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Reflect.apply

静态方法?Reflect.apply()通过指定的参数列表发起对目标(target)函数的调用。

语法

代码语言:javascript
复制
Reflect.apply(target, thisArgument, argumentsList)

参数

target目标函数。thisArgumenttarget函数调用时绑定的this对象。argumentsListtarget函数调用时传入的实参列表,该参数应该是一个类数组的对象。

返回值

使用指定的this值和参数调用给定的目标函数的结果。

异常

如果target对象不可调用,抛出TypeError

描述

该方法与ES5中Function.prototype.apply()方法类似:调用一个方法并且显式地指定this变量和参数列表(arguments)?,参数列表可以是数组,或类似数组的对象。

代码语言:javascript
复制
Function.prototype.apply.call(Math.floor, undefined, [1.75]);

使用?Reflect.apply?方法会使代码更加简洁易懂。

示例

使用Reflect.apply()

代码语言:javascript
复制
Reflect.apply(Math.floor, undefined, [1.75]); 
// 1;

Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111]);
// "hello"

Reflect.apply(RegExp.prototype.exec, /ab/, ['confabulation']).index;
// 4

Reflect.apply(''.charAt, 'ponies', [3]);
// "i"

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Reflect.apply' in that specification.

Standard

Initial definition.

ECMAScript Latest Draft (ECMA-262)The definition of 'Reflect.apply' in that specification.

Draft

?

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

49

12

42 (42)

No support

36

10

Feature

Android

Chrome for Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

49

(Yes)

42.0 (42)

No support

No support

10

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com