我有一个范围问题,我很难解决。
我将getTrackNotes导入到es6模块中,我想按照下面的内容在React类中引用它,但这被设置为Track(React Class)。
我如何参考?
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));
}
答案 0 :(得分:3)
您的getTrackNotes
函数将从顶级作用域继承,但您使用相同的名称函数参数覆盖它。只需从函数参数列表中删除getTrackNotes
或将参数重命名为其他内容:
function updateTimeSequencer (socket, state, thisIsSomethingElse, TimeSequencer, instruments, trackId)