This morning I stumbled upon a tweet from Šime Vidas , where he presented the following use case superfor object literals:
let A = {
run() {
console.log('A runs');
}
};
let B = {
run() {
super.run();
}
};
Object.setPrototypeOf(B, A);
B.run();
This works, and the assignment seems to B.__proto__ = A;work in both Firefox and Chrome.
So, I decided that I can do the same with Object.create:
let A = {
run() {
console.log('A runs');
}
};
let B = Object.create(A);
B.run = function() { super.run() };
Unfortunately, this leads to an error in Firefox:
SyntaxError: using super-properties is only available within methods or eval code in methods
And Chrome:
Untrained SyntaxError: the keyword “super” is unexpectedly here
The same thing happens when I try to pass a property descriptor object to the second argument Object.create.
, , , ( - ?).
, ( )? - , Object.create, ?