How it works...

As we saw previously, the two syntaxes are equivalent. The two methods are defined as properties with function values, and because they don't have any attributes that prevent it, they can be overridden. Both method0 and method1 are defined on the initial object and executed immediately thereafter.

Next, we assign a new function value to those properties of the same object. So when they are called again, the new functions are executed, rather than the originals.

In future recipes, we'll see how to prevent this kind of overriding.

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.