Baseline Widely available
éç㪠Reflect.getPrototypeOf()
ã¡ã½ããã¯ãObject.getPrototypeOf()
ã¨ã»ã¼åãã¡ã½ããã§ããããã¯æå®ãããªãã¸ã§ã¯ãã®ãããã¿ã¤ã (ã¤ã¾ããå
é¨ã® [[Prototype]]
ããããã£ã®å¤) ãè¿ãã¾ãã
const object1 = {
property1: 42,
};
const proto1 = Reflect.getPrototypeOf(object1);
console.log(proto1);
// Expected output: Object { }
console.log(Reflect.getPrototypeOf(proto1));
// Expected output: null
æ§æ
Reflect.getPrototypeOf(target)弿°
target
ãããã¿ã¤ããåå¾ãã対象ã®ãªãã¸ã§ã¯ãã§ãã
ä¸ãããããªãã¸ã§ã¯ãã®ãããã¿ã¤ãã§ããç¶æ¿ãããããããã£ããªãå ´åãnull
ãè¿ãã¾ãã
target
ã Object
ã§ãªãå ´åã« TypeError
ãã¹ãã¼ããã¾ãã
Reflect.getPrototypeOf
ã¡ã½ããã¯ãæå®ãããªãã¸ã§ã¯ãã®ãããã¿ã¤ã (ã¤ã¾ããå
é¨ã® [[Prototype]]
ããããã£ã®å¤) ãè¿ãã¾ãã
Reflect.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf(Object.prototype); // null
Reflect.getPrototypeOf(Object.create(null)); // null
Object.getPrototypeOf() ã¨ã®æ¯è¼
// Object ã®çµæã¯åãã§ã
Object.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf({}); // Object.prototype
// ES5 ä¸ã§ã¯éObjectã®çµæã¯ä¸¡æ¹ã¨ãä¾å¤ã§ã
Object.getPrototypeOf("foo"); // Throws TypeError
Reflect.getPrototypeOf("foo"); // Throws TypeError
// ES2015 ä¸ã§ã¯ Reflect ã®ã¿ä¾å¤ã§ãObject 㯠éObject ã Object ã¨ãã¦æ±ãã¾ã
Object.getPrototypeOf("foo"); // String.prototype
Reflect.getPrototypeOf("foo"); // Throws TypeError
// To mimic the Object ES2015 behavior you need to coerce
Reflect.getPrototypeOf(Object("foo")); // String.prototype
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
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