Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

protoypes in constructor functions in javascript

function Person() {
    this.name = 'John'
}

// adding property 
Person.prototype.name = 'Peter';
Person.prototype.age = 23

const person1 = new Person();

console.log(person1.name); // John
console.log(person1.age); // 23
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #protoypes #constructor #functions #javascript
ADD COMMENT
Topic
Name
3+2 =