摆脱 CoffeeScript 的闭包包装 [英] Getting rid of CoffeeScript's closure wrapper

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

问题描述

我怎样才能省略在全局范围内隐藏我的变量的自动闭包包装器?

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

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

只是在使用 CoffeeScript+SproutCore,当然,我更愿意保持原样:在这种情况下,不需要保护任何内容不被覆盖.

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.

我知道我可以在声明中使用 @this.,但这不太优雅.

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

推荐答案

快速而肮脏的解决方案:使用控制台标志 -b(裸).警告:如果你这样做,小猫会死!

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 的闭包包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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