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 has 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>