我有一个要解决的范围问题。
我将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)
关于javascript - React.createClass内的范围问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39534165/