Skip to content

Surplus & this #71

Open
Open
@philipahlberg

Description

I'm trying to create a web component using Surplus. The web component implements a render() method that returns a DOM node created with Surplus. However, I am unable to access this in certain situations because Surplus generates a bunch of IIFEs inside the render call.

Consider the following:

<button onClick={this.onClick}>Click me!</button>

The output of the code above is this:

(function () {
    var __;
    __ = createElement("button", null, null);
    __.onclick = this.onClick;
    __.textContent = "Click me!";
    return __;
})()

Because of the surrounding anonymous function, this is no longer the same as it was before, and thus I get an error (Cannot read property 'onClick' of undefined).

Is it possible for the compiler to emit arrow functions instead of regular functions? Could that fix the issue?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions