Home » Javascript Object setPrototypeOf() Method

Javascript Object setPrototypeOf() Method

by Online Tutorials Library

JavaScript Object.setPrototypeOf() Method

The Object.setPrototypeOf() method sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null. All JavaScript objects inherit properties and methods from a prototype. It is generally considered the proper way to set the prototype of an object.

Syntax:

Parameters:

obj: It is the object which is to have its prototype set.

Prototype: It is the object’s new prototype (an object or null).

Return value:

This method returns the specified object.

Browser Support:

Chrome 34
Edge Yes
Firefox 31
Opera Yes

Example 1

Output:

 [object Object] {    drive: drive() {      return 'Add raay';    },    net: net() {      return 'use net';    }  }  "use net"  "Add raay"  

Example 2

Output:

"people makes"  

Example 3

Output:

[object Object] {   drive: drive() {      return 'driving toyota';   },    wifi: wifi() {      return 'carry';    }  }  "carry"  

Next TopicJavaScript Objects

You may also like