【问题标题】:How to write a closure in livescript?如何在 livescript 中编写闭包?
【发布时间】:2017-03-26 11:20:35
【问题描述】:

如何在 livescript 中编写闭包

for i from 1 to 10
  cb = -> console.log i
  set-timeout cb, i*1000

得到 1 到 10 而不是 10 的 10 倍?

【问题讨论】:

    标签: closures livescript


    【解决方案1】:
    for let i from 1 to 10
      cb = -> console.log i
      set-timeout cb, i*1000
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-29
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 2010-11-10
      相关资源
      最近更新 更多