首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Reflect.setPrototypeOf

静态方法Reflect.setPrototypeOf()Object.setPrototypeOf()方法是一致的。它将指定对象的原型 (即,内部的[[Prototype]]?属性)设置为另一个对象或为?null

语法

代码语言:javascript
复制
Reflect.setPrototypeOf(target, prototype)

参数

target设置原型的目标对象。prototype对象的新原型 (一个对象或null)。

返回值

返回一个Boolean值表明是否原型已经成功设置。

异常

抛出一个TypeError异常,如果目标不是?Object,或原型不是一个对象或不为?null

描述

Reflect.setPrototypeOf方法改变指定对象的原型 (即,内部的?[[Prototype]]属性值)。

示例

使用Reflect.setPrototypeOf()

代码语言:javascript
复制
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.
var target = {};
var proto = Object.create(target);
Reflect.setPrototypeOf(target, proto); // false

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Reflect.setPrototypeOf' in that specification.

Standard

Initial definition.

ECMAScript Latest Draft (ECMA-262)The definition of 'Reflect.setPrototypeOf' in that specification.

Draft

?

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

49

(Yes)

42 (42)

No support

No support

10

Feature

Android

Chrome for Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

49

(Yes)

42.0 (42)

No support

No support

10

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com