摆脱CoffeeScript的闭包

摆脱CoffeeScript的闭包

本文介绍了摆脱CoffeeScript的闭包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 (function(){
//我的编译代码
})。call(this);

只是使用CoffeeScript + SproutCore,当然,



我知道我可以使用 @

解决方案

快速和脏的解决方案:使用控制台标志 -b (裸)。 警告:小猫会死亡。



清洁解决方案:不要这样做。

 用法:coffee [options] path / to / script.coffee 

-c, - compile编译为JavaScript并另存为.js文件
-i,--interactive运行交互式CoffeeScript REPL
-o,--output设置编译JavaScript的目录
-j,--join在编译之前连接脚本
-w, - 观察脚本的变化,并重新编译
-p,--print将编译的JavaScript打印到stdout
-l,--lint通过JSLint管道编译的JavaScript
-s,--stdio通过stdio监听和编译脚本
-e,--eval从命令行编译字符串
-r,--require在执行脚本之前需要一个库
-b, - 无需顶层函数包装器编译
-t,--tokens打印lexer生成的令牌
-n,--nodes打印Jison生成的解析树
--nodejs传递选项到node二进制
-v,--version显示CoffeeScript版本
-h,--help显示此帮助消息


How can I omit the automatic closure wrappers that hides my variables from the global scope?

(function() {
  // my compiled code
}).call(this);

Just playing around with CoffeeScript+SproutCore, and of course, I'd prefer to leave the scope as it is: in this case there is no need to protect anything from overwriting.

I know I can use @ or this. at the declaration, but that's not too elegant.

解决方案

Quick and dirty solution: Use the console flag -b (bare). Warning: Kittens will die if you do that!

Clean solution: Don't do that.

Usage: coffee [options] path/to/script.coffee

  -c, --compile      compile to JavaScript and save as .js files
  -i, --interactive  run an interactive CoffeeScript REPL
  -o, --output       set the directory for compiled JavaScript
  -j, --join         concatenate the scripts before compiling
  -w, --watch        watch scripts for changes, and recompile
  -p, --print        print the compiled JavaScript to stdout
  -l, --lint         pipe the compiled JavaScript through JSLint
  -s, --stdio        listen for and compile scripts over stdio
  -e, --eval         compile a string from the command line
  -r, --require      require a library before executing your script
  -b, --bare         compile without the top-level function wrapper
  -t, --tokens       print the tokens that the lexer produces
  -n, --nodes        print the parse tree that Jison produces
      --nodejs       pass options through to the "node" binary
  -v, --version      display CoffeeScript version
  -h, --help         display this help message

这篇关于摆脱CoffeeScript的闭包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:55