Javascript - Method

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





Discover More
Javascript Function Method
Javascript - Functions

Functions functionalities in Javascript. A function in Javascript is a variable that’s given a reference to the function being declared. The function itself is a value (as an integer or an array) that...



Share this page:
Follow us:
Task Runner