2

I want to Subclass a Proxied ES6 Class. It works just fine in Firefox and Chrome, but Safari 10 throws an error:

let SuperClass = class {
    constructor() {
        console.log('SuperClass constructor')
    }
}

let ProxiedSuperClass = new Proxy(SuperClass, {});

let SubClass = class extends ProxiedSuperClass {
    constructor() {
        super();
        console.log('SubClass constructor')
    }
}

var s = new SubClass(); 

// Expected output (Firefox, Chrome): 
// SuperClass constructor
// SubClass constructor

// Safari output:
// function is not a constructor (evaluating 'super()')

So, Safari seems to try to extend Proxy, while Firefox and Chrome extend SuperClass.

What's the correct behaviour here? Is it just not possible (or well defined) to proxy a Class? Or can I somehow hint Safari to do "the right thing", i.e. to subclass SuperClass instead of Proxy?

phoboslab
  • 41
  • 1
  • 6
  • 1
    When you proxy a class, you're really only registering traps on that constructor function and any properties directly defined on it. The new (class) function still has its original constructor and prototype chain. – Alnitak Feb 27 '17 at 17:03
  • That's what I thought - the proxy should behave like the original object, unless you register traps that do something else. So I guess I should file a bug report with Webkit then? – phoboslab Feb 27 '17 at 17:19
  • 1
    I think so - might be worth waiting for other answers, though. I've never used `Proxy` myself, but the Firefox and Chrome behaviour sounds correct to me. – Alnitak Feb 27 '17 at 17:38

0 Answers0