Reflect 是一个内置的对象,它提供拦截 JavaScript 操作的方法。这些方法与处理器对象的方法相同。Reflect不是一个函数对象,因此它是不可构造的。

描述

与大多数全局对象不同,Reflect没有构造函数。你不能将其与一个new运算符一起使用,或者将Reflect对象作为一个函数来调用。Reflect的所有属性和方法都是静态的(就像Math对象)。

方法

Reflect对象提供以下静态函数,它们具有与处理器对象方法相同的名称。这些方法中的一些与 Object 上的对应方法相同。

Reflect.apply()
对一个函数进行调用操作,同时可以传入一个数组作为调用参数。和 Function.prototype.apply() 功能类似。
Reflect.construct()
对构造函数进行 new 操作,相当于执行 new target(...args)
Reflect.defineProperty()
Object.defineProperty() 类似。
Reflect.deleteProperty()
作为函数的delete操作符,相当于执行 delete target[name]
Reflect.enumerate()
该方法会返回一个包含有目标对象身上所有可枚举的自身字符串属性以及继承字符串属性的迭代器,for...in 操作遍历到的正是这些属性。
Reflect.get()
获取对象身上某个属性的值,类似于 target[name]。
Reflect.getOwnPropertyDescriptor()
类似于 Object.getOwnPropertyDescriptor()
Reflect.getPrototypeOf()
类似于 Object.getPrototypeOf()
Reflect.has()
判断一个对象是否存在某个属性,和 in 运算符 的功能完全相同。
Reflect.isExtensible()
类似于 Object.isExtensible().
Reflect.ownKeys()
返回一个包含所有自身属性(不包含继承属性)的数组。
Reflect.preventExtensions()
类似于 Object.preventExtensions()。返回一个Boolean
Reflect.set()
将值分配给属性的函数。返回一个Boolean,如果更新成功,则返回true
Reflect.setPrototypeOf()
类似于 Object.setPrototypeOf()

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
Reflect
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
Reflect
Draft Reflect.enumerate has been removed.

浏览器兼容

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
applyChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
constructChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
definePropertyChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
deletePropertyChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
enumerate
DeprecatedNon-standard
Chrome No support NoEdge No support ? — 15Firefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
getChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
getOwnPropertyDescriptorChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
getPrototypeOfChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
hasChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
isExtensibleChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
ownKeysChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
preventExtensionsChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
setChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
setPrototypeOfChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0

Legend

Full support  
Full support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

相关链接

文档标签和贡献者

此页面的贡献者: xyy94813, zhangchen, xgqfrms-GitHub, mo-n, wzx, ziyunfei
最后编辑者: xyy94813,