Good question... The code that I used in the example uses a shortcut syntax, which was introduced in ECMAScript 2015. You can also use a key and then a function as a value. If you run the code below in your browser console, both calls would work.
let obj1 = {
doSomething1(){
console.log("Hi, from inside doSomething1");
},
doSomething2: function(){ console.log("Hi, from inside
the doSomething2");
}
}
obj1.doSomething1();
obj1.doSomething2();
You know, I used to hate all the syntactic sugar when I first started learning js cuz it all seemed so overwhelming but the more I learn the more i can appreciate it. Nice job, and thanks for explaining this to me. I’m gonna be on the look out for more videos like this.
1
u/Al_Maleech_Abaz Mar 19 '21
Nice explanation. Wouldn’t the function here need to have a key associated with it, or is the function name implied as the key?