Javascript 如何在coffeescript上创建音频统一事件

Javascript 如何在coffeescript上创建音频统一事件,javascript,coffeescript,atom-editor,babeljs,Javascript,Coffeescript,Atom Editor,Babeljs,当音频以coffeescript结尾时,我试图调用一个函数,我用javascript编写了文本代码,它工作得很好,但在coffeescript中没有 下面是coffeescript的全部代码 播放:()-> 如果(@getConfig“musicPath”)!=“./音频剪辑/背景音乐/” @pathtoMusic=@getConfig“musicPath” 其他的 @pathtoMusic=path.join(uu dirname,@getConfig“musicPath”) @musicFi

当音频以coffeescript结尾时,我试图调用一个函数,我用javascript编写了文本代码,它工作得很好,但在coffeescript中没有

下面是coffeescript的全部代码

播放:()->
如果(@getConfig“musicPath”)!=“./音频剪辑/背景音乐/”
@pathtoMusic=@getConfig“musicPath”
其他的
@pathtoMusic=path.join(uu dirname,@getConfig“musicPath”)
@musicFiles=fs.readdirSync(@pathtoMusic.toString())
@音乐=新音频(@pathtoMusic+@musicFiles[0])
@music.volume=@getConfig“musicVolume”
@如果(@music.paused),isplay=false
如果@isplay,则返回null
@isplay=true
@音乐播放
@music.onended=->
@music.play()/----这里不起作用------//
我使用atom文本编辑器在一个包中对coffeescript代码进行rum,并使用chrome对javascript代码进行rum

具体来说。我在atom上看到了一个使用onended事件的包,下面是代码

代码冠军

我使用在线转换器将babel代码转换为javascript,得到了这个结果

巴别塔到javascript

然后我将javascript代码转换为coffeescript编译器,得到了这个

javascript到coffeescript


但是代码只对巴贝尔有效。我不知道我做错了什么

您可能希望使用coffeescript中的fat arrow函数来绑定您的“this”:


如果您可以发布更多的内容,这可能会有所帮助。

音频正常播放,但在结束时什么也不做。没问题!那么你介意把它作为解决方案吗?
'use babel';

epicVictory() {
      if (this.isPlaying) return
      console.log('Epic Victory!');
      let maxIndex = this.winFiles.length - 1
      let minIndex = 0
      let randomIndex = Math.floor(Math.random() * (maxIndex - minIndex + 1) + minIndex)
      this.audio = new Audio(this.winpath + this.winFiles[randomIndex])

      this.audio.onended = () => {
          this.audio.play() //-------here work-----//
          //this.isPlaying = false
      }

  this.isPlaying = true

  this.audio.volume = this.volume
  this.audio.play()
  return true
},
//imput
this.music.onended = () => {
    this.audio.play()
}

//ouput
this.music.onended = function () {
    this.music.play();
};
//imput
this.music.onended = function () {
    this.autoPlay();
}

//ouput
@music.onended = ->
  @music.play()
@music.onended = =>
 @autoPlay()