Below code demonstrates - how to create a constructor with parameters:
//creating a generic blueprint
function Person(name, age) {
this.name = name;
this.age = age;
}
var person1 = new Person("Anna",37);
var person2 = new Person("Steffi",37);
console.log(person1.name);
console.log(person2.name);
Refer:
Practice at:
http://jsbin.com
//creating a generic blueprint
function Person(name, age) {
this.name = name;
this.age = age;
}
var person1 = new Person("Anna",37);
var person2 = new Person("Steffi",37);
console.log(person1.name);
console.log(person2.name);
Refer:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor
Practice at:
http://jsbin.com
No comments:
Post a Comment