為什么bind中的回調(diào)函數(shù)不使用簡寫就沒有效果呢?而且也沒有報(bào)錯(使用箭頭函數(shù)是沒有問題的)
componentDidMount(){
????????$('#player').jPlayer({
????????????ready:?function?()?{
????????????????$(this).jPlayer('setMedia',?{
????????????????????mp3?:?'http://oj4t8z2d5.bkt.clouddn.com/%E9%AD%94%E9%AC%BC%E4%B8%AD%E7%9A%84%E5%A4%A9%E4%BD%BF.mp3'
????????????????}).jPlayer('play');
????????????},
????????????supplied:?'mp3',
????????????wmode:?'window'
????????});
????????//綁定監(jiān)聽事件
????????$('#player').bind($.jPlayer.event.timeupdate,function(e){
????????????this.setState({
????????????????progress?:?Math.round(e.jPlayer.status.currentTime)
????????????});
????????});
????}
2018-03-06
function函數(shù)改變了this指向,而es6寫法未改變,你可以分別打印出來看看this是什么:console.log(this)