Defining function properties as methods on a plain object

Defining methods on object literals has always been possible with normal key-value pairs. More recent versions of ECMAScript have added a shorthand that mimics the syntax for defining methods on classes.

In this recipe, we'll see that we can create and override methods on object literals using either technique.

Get ECMAScript Cookbook 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.