August 2016
Intermediate to advanced
635 pages
14h 5m
English
Instance properties are the properties that are part of the object instance itself, as shown in the following example:
function Player() {
this.isAvailable = function() {
return "Instance method says - he is hired";
};
}
Player.prototype.isAvailable = function() {
return "Prototype method says - he is Not hired";
};
var crazyBob = new Player();
console.log(crazyBob.isAvailable());When you run this example, you will see that Instance method says - he is hired is printed. The isAvailable() function defined in the Player() function is called an instance of Player. This means that apart from attaching properties via the prototype, you can use the this keyword to initialize properties in a constructor. ...