💠[[HomeObject]]
🚧 under construction
Last updated
Was this helpful?
🚧 under construction
Last updated
Was this helpful?
Was this helpful?
not as nonMethod: function()
(non-method syntax)
const { log } = console;
// -------------------------------------------------------------
// ⭐️ only methods have [[HomeObject]].
// ⭐️ `super` can only be used in a method (with [[HomeObject]])
// ⭐️ super === [[HomeObject]].[[Prototype]]
// -------------------------------------------------------------
// ❌ regular function
// --------------------
function f1(){ super.method() }
// ^^^^^ // ⛔️ SyntaxError: 'super' unexpected here.
// ❌ arrow function (not in a method)
// ------------------------------------
let f2 = () => super.method();
// ^^^^^ // ⛔️ SyntaxError: 'super' unexpected here.
const a = {
// ❌ object property (function as property value)
// ------------------------------------------------
nonMethod: function(){ super.method() }
// ^^^^^ // ⛔️ SyntaxError: 'super' unexpected here.
}
const b = {
// ✅ object method:
// ------------------
// • [[HomeObject]] === b
// • super === [[HomeObject]].[[Prototype]]
// === b.[[Prototype]]
// === Object.prototype
method(){ log(`${super.constructor.name}`) }
}
b.method(); // Object