According to the Mozilla Developer Network, the definition of an object in JS is:
"An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. "
To me this means an object's method should be a key, value pair. Like this:
var myObject = {
info: 'Im an object',
sayInfo: function() {
console.log(this.info);
}
};
Above, the method is the key called "sayInfo" and the value is a function which logs to the console.
But I've seen a method on an object defined this way:
var myObject = {
info: 'Im an object',
sayInfo() {
console.log(this.info);
}
};
I don't understand how the method sayInfo is syntactically possible because it is not a key, value pair. How is it possible to define a method this way?