Reflect.getPrototypeOf()
JavaScript Reflect.getPrototypeOf()方法
静态的
Reflect.getPrototypeOf()方法用于返回指定对象的原型。与方法Object.getProtptypeOf()相同。
语法:
Reflect.getPrototypeOf(obj)
参数:
obj:它是获取原型的目标对象。
返回值:
此方法返回给定对象的原型。
例外:
如果将无效的目标(例如Number或String文字),null或undefined赋予它,则为TypeError。
浏览器支持:
浏览器 |
版本 |
Chrome |
49 |
Edge |
12 |
Firefox |
42 |
Opera |
36 |
示例1
// create a object with no parent
const h = Object.create (null);
console.log (
Reflect.getPrototypeOf ( h ) === null
);
输出:
示例2
const hurry1 = {
property1: 42
};
const hello = Reflect.getPrototypeOf(hurry1);
console.log(hello);
输出:
示例3
const hurry1 = {
property1: 42
};
const hello = Reflect.getPrototypeOf(hurry1);
console.log(Reflect.getPrototypeOf(hello));
输出: