简体   繁体   English

React.createClass内的范围问题

[英]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). 我将getTrackNotes导入到es6模块中,并且我想按照以下内容在React类中引用它,但这设置为Track(React类)。

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. 您的getTrackNotes函数将从顶部作用域继承,但是您正在使用相同的name函数参数覆盖它。 Just remove getTrackNotes from the function arguments list or rename the argument to something else: 只需从函数参数列表中删除getTrackNotes或将参数重命名为其他名称即可:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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