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()
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. |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | 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 | 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 | 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 |