📅  最后修改于: 2020-10-25 09:14:55             🧑  作者: Mango
handler.getPrototypeOf()方法是内部方法的陷阱。如果target是不可扩展的,则此方法返回与Object.getPrototypeOf(target)相同的值。
getPrototypeOf(target)
target:目标对象。
此方法返回一个对象或null。
Chrome | NO |
Edge | NO |
Firefox | 49 |
Opera | NO |
const obj = {};
const proto = {};
const hag = {
getPrototypeOf(target) {
document.writeln (target === obj);
document.writeln (this === hag);
return proto;
}
};
const p = new Proxy(obj, hag);
document.writeln(Object.getPrototypeOf(p) === proto);
输出:
true true true
var obj = {};
var p = new Proxy(obj, {
getPrototypeOf(target) {
return Array.prototype;
}
});
document.write(
p instanceof Array
);
输出:
true
const Prototype = {
eyeCount : 32
};
const handler = {
getPrototypeOf(target) {
return Prototype;
}
};
const obj = new Proxy(Prototype, handler);
document.writeln(Object.getPrototypeOf(obj) == Prototype);
输出:
true