.bind函数与CoffeeScript [英] .bind function with CoffeeScript

查看:123
本文介绍了.bind函数与CoffeeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I try to convert the following snippet of code ...

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

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

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

但是,当你尝试编译它的代码是不正确的,你回来错误意外的'。'

However that code is incorrect when you try to compile it you get back Error Unexpected '.'

在这个正确的方式使用.bind函数使用CoffeeScript的情况?

What would the correct way to use the .bind function in this situation using CoffeeScript be?

推荐答案

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

这篇关于.bind函数与CoffeeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆