当前位置:首页 > 手册大全 > javascript手册 > Reflect

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
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Basic support Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
apply Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
construct Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
defineProperty Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
deleteProperty Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
enumerate
DeprecatedNon-standard
Chrome No support No Edge No support ? — 15 Firefox No support No IE No support No Opera No support No Safari No support No WebView Android No support No Chrome Android No support No Edge Mobile No support No Firefox Android No support No Opera Android No support No Safari iOS No support No Samsung Internet Android No support No nodejs No support No
get Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
getOwnPropertyDescriptor Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
getPrototypeOf Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
has Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
isExtensible Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
ownKeys Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
preventExtensions Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
set Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs Full support 6.0.0
setPrototypeOf Chrome Full support 49 Edge Full support 12 Firefox Full support 42 IE No support No Opera Full support 36 Safari Full support 10 WebView Android Full support 49 Chrome Android Full support 49 Edge Mobile Full support Yes Firefox Android Full support 42 Opera Android Full support 36 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs 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.

相关链接

公益性全栈资源网站,鸣谢默默付出的博主、工程师、架构师们。
网站内容来源技术大牛的辛勤结晶。
81For 技术网站 Copyright ©2019 备案号:津ICP备19001147号-2