Created: 2017.04.13
True 'Object Literal' syntax involves creating the object properties as you create the object.
A property can be any valid JavaScript type (string, number, boolean, function, array, etc.).
A method is essentially a property of the object to which you have assigned an anonymous function. So the property is now equal to a function. It is still a property of the object, but because it 'does' something, we now call it a 'method'.
var myObj = {
property1: 'foo',
property2: 'bar',
property3_is_a_method: function() {
console.log('hello world');
}
};
console.log(myObj);
Alternatively, you can assign an empty object to a variable, and then assign properties to the object:
var myObj = {};
myObj.property1 = 'foo';
myObj.property2 = 'bar';
myObj.property3_is_a_method = function() {
console.log('hello world');
};