Skip to content

Not es6 ready - does not work with es6 classes #181

@OJezu

Description

@OJezu

If I declare class using es6 class keyword:

class Foo {
    constructor(foo, bar) {}
}
module.exports = Foo;

And I try to load it using wire:

wire({
   "foo": {
        "module": "Foo",
        "args": ["monty", "python"],
    },
});

I get an error:

TypeError: Class constructors cannot be invoked without 'new'
    at BrowserConnectionFactory ()
    at instantiate (.../node_modules/wire/lib/instantiate.js:37:20)
    at createInstance (.../node_modules/wire/lib/plugin/basePlugin.js:250:7)

Wire (actually when) is trying to do Foo.apply(new_foo, args), which is not allowed in es6. Solution would be using new spread operator - new Foo(...args) , but that is not backwards-compatible.
PR #180 has possible workaround with named constructors which can be called with "apply".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions