2016-09-16 84 views
2

我有一個範圍問題,我正在努力解決。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)); 
    } 

回答

3

getTrackNotes功能會從頂部範圍被繼承,但是你是一個同名函數參數覆蓋它。單從函數的參數列表中刪除getTrackNotes或重命名參數別的東西:

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

啊,我想知道這到底是怎麼回事,我想試試謝謝 – iKode