Skip to content

CustomEvent could not be extended #3

@Stav88

Description

@Stav88

When I extends CustomEvent using babel the prototype is wrongly set to CustomEventPrototype instead of my class so I can't call methods of my class.

Scenario:

  • Extends CustomEvent using ES6 syntax:
export default class MyEvent extends CustomEvent {
    test() {return 'ok';}
}
  • Construct event and call test() methods:
const evt = new MyEvent();
console.log(Object.getPrototypeOf(evt));
console.log(evt.test());
  • Compile using Babel

Results:

[object CustomEventPrototype]
Object doesn't support property or method 'test'

Expected:

no error

[object MyEvent]
ok

Fix

I find a way to fix that by adding the following code at the end of CustomEvent contructor:

Object.setPrototypeOf(evt, Object.getPrototypeOf(this));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions