Defining methods

ES6 onwards provides a new syntax for defining the methods on an object. The following example demonstrates the new syntax:

let object = {    myFunction(){        console.log("Hello World!!!"); //Output "Hello World!!!"    }}object.myFunction();

This concise function allows the use of super in them, whereas traditional object methods don't allow the use of super. We will learn more about this later in the book.

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.