CodesJava

Easy learning with example program codes

Object.setPrototypeOf() JavaScript JS

The Javascript Object setPrototypeOf() method sets the prototype of a specified object to another object. Prototype can be another object or null.

Syntax:

Object.setPrototypeOf(object, prototype) 

Parameters:
object: It represents the object whose prototype have to be set.
prototype: It represents the new prototype.

Return:
Specified Object

Example:

<!DOCTYPE html>
<html>
<body>
<script>
let jewel = {  
gems() {  
return 'DIAMOND';  }  }  
let jewellery = {  
stones() {  
return 'PLATINUM';  }  }  
Object.setPrototypeOf(jewellery, jewel);  
document.write(jewellery.stones());
</script>
</body>
</html>

Output:

PLATINUM
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status