C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.getPrototypeOf() MethodThe 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) Parameterobj: 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:
Example 1let 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 2const 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 3const 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
|