Difference between revisions of "Constructors"

From rbachwiki
Jump to navigation Jump to search
Line 10: Line 10:
   }
   }
}
}
// create a new Object
var person = new Person("robert",24);
var person = new Person("robert",24);
person.display();
person.display();
</pre>
</pre>

Revision as of 22:23, 20 October 2016

Constructor

function Person(name, age){
  this.name = name;
  this.age=age;
  this.display=function(){
    console.log("My name is " + name);
    console.log("My age is "+ age);
  }
}
// create a new Object
var person = new Person("robert",24);
person.display();