January 2020
Intermediate to advanced
548 pages
13h 36m
English
Method definitions were added to the language at the same time as class definitions to allow you to easily declare methods bound to a specific object. They are not limited to class definitions, though. You can use them freely in object literals as well:
const things = { myFunction() { // ... }};
In classes, you can also declare methods in this manner:
class Things { myFunction() { // ... }}
You can also use traditional styles of function definition to declare your methods, such as a function expression assigned to an identifier:
class Things { myFunction = function() { // ... };}
There is, however, a crucial difference between method definitions and other styles of function definition. A method definition will always be ...
Read now
Unlock full access