📘Reflect
JS ⟩ object ⟩ built-in ⟩ Reflect
A built-in object that provides methods for interceptable operations. The methods are the same as those of proxy handlers.
Reflect is not a function object, so it's not constructible❗
the first parameter to all the Reflect methods is called the target parameter.
apply(f, o, args)
invokes
f
as a method ofo
, just likeo.f(args)
.same as
f.apply(o, args)
.
construct(C, args, newTarget)
invokes
C
as a constructor.same as
new C(...args)
.newTarget
is used as new.target (if specified).
defineProperty(o, key, desc)
define new/existing property.
similar to Object.defineProperty(o, key, desc).
but returns boolean.
deleteProperty(o, key)
delete a property.
similar to
delete o[key]
.returns boolean.
getOwnPropertyDescriptor(o, key)
get a property descriptor.
(almost) same as Object.getOwnPropertyDescriptor(o, key)
get the prototype of an object.
(almost) same as Object.getPrototypeOf(o).
has(o, key)
check if object
o
has propertykey
.similar to
key in o
.returns
true
for any inherited properties.
isExtensible(o)
check if an object is extensible.
(almost) same as Object.isExtensible(o)
ownKeys(o)
returns an array of own property keys. (string/symbol included)
similar to Object.getOwnPropertyNames(o) + Object.getOwnPropertySymbols(o).
prevents new properties from being added to an object.
(almost) same as Object.preventExtensions(o)
set(o, key, value, receiver)
set a property.
similar to
o[key] = value
.returns boolean.
(not sure what the receiver is for 😕) ❓
setPrototypeOf(o, p)
set the prototype of an object. (not recommended)
similar to Object.setPrototypeOf(o, p).
returns boolean.
Last updated