Skip to content

Why have to bind this in router function? #342

@krave1986

Description

@krave1986

I am researching some example code about React based on director.js.
The example code shows that I have to bind thisArg to make sure the app could work well.
Could you please tell me why I have to bind this in router function?
Here is the snippet of the code.

        componentDidMount: function () {
            var setState = this.setState;
            var router = Router({
                '/': setState.bind(this, {nowShowing: app.ALL_TODOS}),
                '/active': setState.bind(this, {nowShowing: app.ACTIVE_TODOS}),
                '/completed': setState.bind(this, {nowShowing: app.COMPLETED_TODOS})
            });
            router.init('/');
        },

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