The `super` keyword doesn't work as it should?

/#!/JoePea joe at
Mon Jul 18 21:00:26 UTC 2016

For example, both of these examples don't work in Chrome:

function A() {
A.prototype.constructor = A
A.prototype.hello = function() {
    return 'hello'

function B() {
    // super()
B.prototype = Object.create(A.prototype)
B.prototype.constructor = B
B.prototype.hello = function() {
    return super.hello() + 'there'

new B


let obj1 = {
    hello() {
        return 'hello'
    sayHello() {

console.log('Obj1 says hello:')

let obj2 = Object.create(obj1)
Object.assign(obj2, {
    hello() {
        return super.hello() + 'there.'

console.log('Obj2 says hello:')
obj2.sayHello() // Error

I was hoping `super` was more flexible than that.

For example, in the first snippet, why can't `super` simply be a shortcut
for "look up the prototype of the object that the method is called on, then
find the `.constructor` property and call it on `this`"? That seems to be
simple. It could throw an error if `.constructor` is not found, in the case
of ES5-style classes that aren't defined using that pattern that ES6
classes are syntax sugar for.

And in the second example, why does `super.hello` not work as expected?

I believe that these limitations may severely limit my ability to create
the multiple-inheritance tool that I'm imagining over at

Any ideas or suggestions?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list