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:

Chrome34
EdgeYes
Firefox31
OperaYes

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"





Latest Courses