TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript handler getPrototypeOf() Method

JavaScript handler getPrototypeOf() Method with examples on javascript handler, javascript methods, javascript tutorial, apply(), construct(), defineProperty(), deleteProperty(), get(), setPrototypeOf(), set(), ownKeys(), isExtensible() etc.

<< Back to JAVASCRIPT

JavaScript handler.getPrototypeOf() Method

The 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 value

This method returns an object or null.

Browser Support

Chrome NO
Edge NO
Firefox 49
Opera NO

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); 
Test it Now

Output:

true true true

Example 2

var obj = {};
var p = new Proxy(obj, {
    getPrototypeOf(target) {
        return Array.prototype;
    }
});
document.write(
  
    p instanceof Array  
);
Test it Now

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);
Test it Now

Output:

true

Next TopicJavaScript handler




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf