静态
Reflect
.setPrototypeOf()
method is the same method as
Object.setPrototypeOf()
, except for its return type. It sets the prototype (i.e., the internal
[[Prototype]]
property) of a specified object to another object or to
null
,并返回
true
if the operation was successful, or
false
otherwise
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Reflect.setPrototypeOf(target, prototype)
target
The target object of which to set the prototype.
prototype
null
).
A
布尔
indicating whether or not the prototype was successfully set.
A
TypeError
, if
target
is not an
Object
or if
prototype
is neither an object nor
null
.
Reflect.setPrototypeOf
method changes the prototype (i.e. the value of the internal
[[Prototype]]
property) of the specified object.
Reflect.setPrototypeOf()
Reflect.setPrototypeOf({}, Object.prototype) // true
// It can change an object's [[Prototype]] to null.
Reflect.setPrototypeOf({}, null) // true
// Returns false if target is not extensible.
Reflect.setPrototypeOf(Object.freeze({}), null) // false
// Returns false if it cause a prototype chain cycle.
let target = {}
let proto = Object.create(target)
Reflect.setPrototypeOf(target, proto) // false
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Reflect.setPrototypeOf' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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()