Baseline Widely available
éç㪠Reflect.setPrototypeOf()
ã¡ã½ããã¯ãè¿å¤ãé¤ãã¦ã Object.setPrototypeOf()
ã¨åãã¡ã½ããã§ããããã¯æå®ããããªãã¸ã§ã¯ãã®ãããã¿ã¤ã (ã¤ã¾ããå
é¨ã® [[Prototype]]
ããããã£) ã«ã»ãã®ãªãã¸ã§ã¯ããã¾ã㯠null
ãè¨å®ããæä½ãæåãããªã true
ããããã§ãªããªã false
ãè¿ãã¾ãã
const object1 = {};
console.log(Reflect.setPrototypeOf(object1, Object.prototype));
// Expected output: true
console.log(Reflect.setPrototypeOf(object1, null));
// Expected output: true
const object2 = {};
console.log(Reflect.setPrototypeOf(Object.freeze(object2), null));
// Expected output: false
æ§æ
Reflect.setPrototypeOf(target, prototype)弿°
target
ãããã¿ã¤ããè¨å®ãã対象ã®ãªãã¸ã§ã¯ãã§ãã
prototype
ãªãã¸ã§ã¯ãã®æ°ãããããã¿ã¤ã (ãªãã¸ã§ã¯ãã¾ã㯠null
) ã§ãã
ãããã¿ã¤ããæ£å¸¸ã«è¨å®ããããã©ããã示ã Boolean
å¤ã§ãã
TypeError
: target
ã Object
ã§ã¯ãªãå ´åãã¾ã㯠prototype
ããªãã¸ã§ã¯ãã§ã null
ã§ããªãå ´åã
Reflect.setPrototypeOf
ã¡ã½ããã¯ãæå®ããããªãã¸ã§ã¯ãã®ãããã¿ã¤ã (ã¤ã¾ããå
é¨ã® [[Prototype]]
ããããã£) ã夿´ãã¾ãã
Reflect.setPrototypeOf({}, Object.prototype); // true
// ãªãã¸ã§ã¯ãã® [[Prototype]] 㯠null ã«å¤æ´ã§ããã
Reflect.setPrototypeOf({}, null); // true
// å¯¾è±¡ãæ¡å¼µã§ããªãå ´åãfalse ãè¿ãã
Reflect.setPrototypeOf(Object.freeze({}), null); // false
// ãããã¿ã¤ããã§ã¼ã³ã循ç°ããå ´åãfalse ãè¿ãã
let target = {};
let proto = Object.create(target);
Reflect.setPrototypeOf(target, proto); // false
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4