C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.getPrototypeOf() MethodThe handler.getPrototypeOf() method is a trap for the internal method. If target is not extensible, then this method returns the same value as Object.getPrototypeOf(target). Syntax
getPrototypeOf(target) Parameters
target: The target object. Return valueThis method returns an object or null. Browser Support
Example 1
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);
Output: true true true Example 2
var obj = {};
var p = new Proxy(obj, {
getPrototypeOf(target) {
return Array.prototype;
}
});
document.write(
p instanceof Array
);
Output: true Example 3
const Prototype = {
eyeCount : 32
};
const handler = {
getPrototypeOf(target) {
return Prototype;
}
};
const obj = new Proxy(Prototype, handler);
document.writeln(Object.getPrototypeOf(obj) == Prototype);
Output: true
Next TopicJavaScript handler
|