.bind function with CoffeeScript

.bind function with CoffeeScript

本文关键字:CoffeeScript with function bind      更新时间:2023-09-26

当我尝试转换以下代码片段时。。。

result.pause = function() {        
  cachedValue = this();
  isPaused(true);
}.bind(result);

使用http://js2coffee.org/它返回

result.pause = ->
  cachedValue = this()
  isPaused true
.bind(result)

但是,当您尝试编译该代码时,会返回错误"

在这种情况下,使用CoffeeScript使用.bind函数的正确方法是什么?

result.pause = (->
  cachedValue = this()
  isPaused true)
.bind(result)