My Profile Photo

Hao's Keeper


A blog to place memos


Method Function

Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. See method definitions for more information.

var obj = {
  foo() {},
  bar() {}
};

Method definitions

Starting with ECMAScript 2015, a shorter syntax for method definitions on objects initializers is introduced. It is a shorthand for a function assigned to the method’s name.

Method

A method is a function which is a property of an object. There are two kind of methods: Instance Methods which are built-in tasks performed by an object instance, or Static Methods which are tasks that are called directly on an object constructor.

Note: In JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function.