簡體   English   中英

React.createClass內的范圍問題

[英]Scope issue inside React.createClass

我有一個要解決的范圍問題。

我將getTrackNotes導入到es6模塊中,並且我想按照以下內容在React類中引用它,但這設置為Track(React類)。

我該如何引用?

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));
     }

您的getTrackNotes函數將從頂部作用域繼承,但是您正在使用相同的name函數參數覆蓋它。 只需從函數參數列表中刪除getTrackNotes或將參數重命名為其他名稱即可:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM