this keyword best practices
//calling a Object's function
var obj = {
property: 1,
func: function() {
return this.property;
}
};
console.log(obj.func()); // outputs 1.
//////// Using this with a prototype function
var o = {
func: function () {
return this.property;
}
};
var obj = Object.create(o, { property: { value: 1}});
console.log(obj.func()); //outputs 1
///////////// Using the this keyword in a Constructor function
function Car(type) {
this.type = type;
this.speed = 0;
}
var bmw = new Car("BMW");
console.log(bmw.type); //outputs "BMW"