Reflect

Reflect 是一个内置的对象,它提供拦截 JavaScript 操作的方法。这些方法与proxy handlers的方法相同。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()
返回一个包含所有自身属性(不包含继承属性)的数组。(类似于 Object.keys(), 但不会受 enumerable影响).
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 Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Reflect 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 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 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 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 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 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
Deprecated Non-standard
Chrome No support No Edge No support 12 — 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 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 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 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 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 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 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 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 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 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 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.

相关链接