TheDeveloperBlog.com

Home | Contact Us

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

Javascript Object getPrototypeOf() Method

Javascript Object getPrototypeOf() Method with example on javascript, object, getOwnPropertySymbols(), getPrototypeOf(), defineProperties(), defineProperty(), entries(), freeze(), javascript tutorial, javascript array etc.

<< Back to JAVASCRIPT

JavaScript Object.getPrototypeOf() Method

The Object.getPrototypeOf() method of JavaScript returns the prototype (i.e. the value of the internal [[Prototype]] property) of the specified object.

Syntax:

Object.getPrototypeOf(obj)

Parameter

obj: It is an object whose prototype is to be returned.

Return value:

This method returns the prototype of the given object. If there are no inherited properties, this method will return null.

Browser Support:

Chrome 5
Edge Yes
Firefox 3.5
Opera 12.1

Example 1

let animal = {
  eats: true
};
   // create a new object with animal as a prototype
let rabbit = Object.create(animal);
alert(Object.getPrototypeOf(rabbit) === animal); // get the prototype of rabbit

Object.setPrototypeOf(rabbit, {}); // change the prototype of rabbit to {}

Output:

true

Example 2

const prototype1 = {};
const object1 = Object.create(prototype1);
const prototype2 = {};
const object2 = Object.create(prototype2);
console.log(Object.getPrototypeOf(object1) === prototype1);
console.log(Object.getPrototypeOf(object1) === prototype2); 

Output:

true
false

Example 3

const prototype1 = {};
const object1 = Object.create(prototype1);
const prototype2 = {};
const object2 = Object.create(prototype2);
console.log(Object.getPrototypeOf(object1) === prototype1);
console.log(Object.getPrototypeOf(object2) === prototype2); 

Output:

true
true

Next TopicJavaScript Objects




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