Javascript - Method

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - About

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

3 - 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());

Advertising
web/javascript/es/method.txt · Last modified: 2019/02/16 17:40 by gerardnico