Javascript Object Prototype

Introduction

Demonstrating the prototype property

Let's add a property to the object class called developed-By


Object.prototype.developedBy = "java2s.com";

// Now we create some objects of different types
function myFunction() {}
let myArray = new Array("apple", "tree", "horse");
let myBool = new Boolean("true");

// Now we test to see how the new property was applied to these descendent objects
console.log(myFunction.developedBy); // w ww  .  j a  v  a  2s .c  o m
console.log(myArray.developedBy); 
console.log(myBool.developedBy); 



PreviousNext

Related