Table of Contents

About

Methods in JavaScript are nothing more than object properties that happen to be functions.

Example

  • Basic:
car = {
   color: "Yellow",
   getColor: function(x){ return this.color; }
}
console.log("The car object has the color "+car.getColor());
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());