function accom () {}; Create a constructor function
Create two objects
var house=new accom ();
var apartment=new accom ();
The object created by the constructor has an attribute constructor, which points to the JavaScript constructor that was used when the object was created.
house.constructor===accom; or house instanceof accom; True
Each constructor in JavaScript has a prototype property that points to an object. When you create an object instance with the keyword new, the properties and methods contained in the instance are derived from the object that prototype points to.
Adding properties and methods to constructors
function accom () {}; Accom.prototype={ false, function() {}}; // adding properties and methods to constructors by object direct amount accom.prototype.rooms=5; // adding attributes by Protype keyword accom.prototype.lock=function() {}; // add a method by using the Protype keyword
A variable defined in its parent function can be accessed in all nested functions
Combining the This and prototype keywords to create constructors (common methods)
function accom (floors,rooms) { this. floors=floors| | 0; // Set Default value 0 this. rooms=rooms| | 7; // Set default value 7 }accom.prototype.lock=function() { this. islock=true ;}; var house=New accom (2,5); // Instantiating Classes
Constructors in JavaScript