Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript Changing Prototype

// constructor function
function Person() {
    this.name = 'John'
}
// add a property
Person.prototype.age = 20;
// creating an object
const person1 = new Person();

console.log(person1.age); // 20

// changing the property value of prototype
Person.prototype = { age: 50 }

// creating new object
const person3 = new Person();

console.log(person3.age); // 50
console.log(person1.age); // 20
 
PREVIOUS NEXT
Tagged: #JavaScript #Changing #Prototype
ADD COMMENT
Topic
Name
5+8 =