I'm just learning Javascript and some new features ES6 etc. With new ES6 style we can define two classless objects like this:
var parent = {
foo() {
console.log("Parent!");
}
}
var child = {
foo() {
super.foo();
console.log("Child!");
}
}
Object.setPrototypeOf(child, parent);
And the call 'super' is working as expected here. But, we also can define the same hierarchy in old style like this:
var parent2 = {
foo: function () {
console.log("Parent!");
}
}
var child2 = {
foo: function () {
super.foor(); // <-- Error
console.log("Child!");
}
}
In this case call to 'super' produces the error "Uncaught SyntaxError: 'super' keyword unexpected here ". So here we can only completely override parent method and cannot call it. To me this behaviour looks absolutely inconsistent. Because both definitions looks same to me! Do I misunderstand something ?