About
Methods in JavaScript are nothing more than object properties that happen to be functions.
Articles Related
Example
- Basic:
car = {
color: "Yellow",
getColor: function(x){ return this.color; }
}
console.log("The car object has the color "+car.getColor());
- same as with Javascript - Object Constructor
function Car(color){
this.color = color;
this.getColor = function(x){ return this.color; };
}
car = new Car("Red");
console.log("The car object has the color "+car.getColor());