Friday, June 15, 2018

JavaScript - Object - constructor with parameters

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

No comments:

Post a Comment