-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
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));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels