简体   繁体   中英

Scope issue inside React.createClass

I have a scope issue that I'm struggling to solve.

I import getTrackNotes into the es6 module, and I want to reference it inside the React class as per the below, but this is set to the Track (React Class).

How can I reference it?

import { getTrackNotes } from '../utils/immutableInstruments';

const Track = React.createClass({

    componentDidMount() {

        const { trackId } = this.props.params;

        function updateTimeSequencer (socket, state, getTrackNotes, TimeSequencer, instruments, trackId)
        {

            //I want to call getTrackNotes here, but the scope is set to the Track React class
            **getTrackNotes();**

        }
        var instruments = this.props.instruments;

        socket.on('state', updateTimeSequencer.bind(this, socket));
     }

Your getTrackNotes function would be inherited from the top scope, but you are overriding it with a same name function argument. Just remove getTrackNotes from the function arguments list or rename the argument to something else:

function updateTimeSequencer (socket, state, thisIsSomethingElse, TimeSequencer, instruments, trackId)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM