This question is derived from super keyword unexpected here
The accepted answer says:
Because super is only valid inside methods.
But in MDN, it seems these two are both methods:
let person = {
greeting() {
return "Hello";
}
};
let friend = {
// shorter syntax for method?
greeting() {
return super.greeting() + ", hi!";
}
// method?
// greeting: function() {
// return super.greeting() + ", hi!"; // Throw error: Uncaught SyntaxError: 'super' keyword unexpected here
// }
};
Object.setPrototypeOf(friend, person);
console.log(friend.greeting());
In understanding es6, Nacholas says:
Attempting to use
super
outside of concise methods results in a syntax error
Methods
were just object properties that contained functions instead of data.Any reference to
super
uses the [[HomeObject]] to determine what to do. The first step is to call Object.getPrototypeOf() on the [[HomeObject]] to retrieve a reference to the prototype. Then, the prototype is searched for a function with the same name. Last, the this binding is set and the method is called.
So it seems [[HomeObject]] is different in shorthand syntax of method? I'm curious why?