Reflect
is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of
proxy handlers
.
Reflect
is not a function object, so it's not constructible.
Unlike most global objects,
Reflect
is not a constructor. You cannot use it with a
new
operator
or invoke the
Reflect
object as a function. All properties and methods of
Reflect
are static (just like the
Math
对象)。
Reflect
object provides the following static functions which have the same names as the
proxy handler methods
.
Some of these methods are also the same as corresponding methods on
Object
, although they do have
some subtle differences
between them.
Reflect.apply(
target
,
thisArgument
,
argumentsList
)
target
function with arguments as specified by the
argumentsList
parameter. See also
Function.prototype.apply()
.
Reflect.construct(
target
,
argumentsList
[,
newTarget
])
new
operator
as a function. Equivalent to calling
new
target
(...
argumentsList
)
. Also provides the option to specify a different prototype.
Reflect.defineProperty(
target
,
propertyKey
,
attributes
)
Object.defineProperty()
. Returns a
布尔
也就是
true
if the property was successfully defined.
Reflect.deleteProperty(
target
,
propertyKey
)
delete
operator
as a function. Equivalent to calling
delete
target
[
propertyKey
]
.
Reflect.get(
target
,
propertyKey
[,
receiver
])
target[propertyKey]
) as a function.
Reflect.getOwnPropertyDescriptor(
target
,
propertyKey
)
Object.getOwnPropertyDescriptor()
. Returns a property descriptor of the given property if it exists on the object,
undefined
否则。
Reflect.getPrototypeOf(
target
)
Object.getPrototypeOf()
.
Reflect.has(
target, propertyKey
)
布尔
indicating whether the target has the property. Either as own or inherited. Works like the
in
operator
as a function.
Reflect.isExtensible(
target
)
Object.isExtensible()
. Returns a
布尔
也就是
true
if the target is extensible.
Reflect.ownKeys(
target
)
Returns an array of the target object's own (not inherited) property keys.
Reflect.preventExtensions(
target
)
Object.preventExtensions()
. Returns a
布尔
也就是
true
if the update was successful.
Reflect.set(
target
,
propertyKey
,
value
[,
receiver
])
布尔
也就是
true
if the update was successful.
Reflect.setPrototypeOf(
target
,
prototype
)
布尔
也就是
true
if the update was successful.
const duck = {
name: 'Maurice',
color: 'white',
greeting: function() {
console.log(`Quaaaack! My name is ${this.name}`);
}
}
Reflect.has(duck, 'color');
// true
Reflect.has(duck, 'haircut');
// false
Reflect.ownKeys(duck); // [ "name", "color", "greeting" ]
Reflect.set(duck, 'eyes', 'black'); // returns "true" if successful // "duck" now contains the property "eyes: 'black'"
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Reflect' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Reflect
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
apply
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
construct
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
defineProperty
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
deleteProperty
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
get
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
getOwnPropertyDescriptor
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
getPrototypeOf
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
has
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
isExtensible
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
ownKeys
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
preventExtensions
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
set
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
setPrototypeOf
|
Chrome 49 | Edge 12 | Firefox 42 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 42 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 6.0.0 |
完整支持
不支持
Reflect
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()