This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 本例是与 NewsWidget 的例子做个对比,以下的代码更科学,对于少用全局变量起到保护作用 | |
| // NewsWidget 的链接: http://css-tricks.com/how-do-you-structure-javascript-the-module-pattern-edition/ | |
| // NewsWidget 的例子,把全局变量 s 作为指向 NewsWidget对象的内部设置,这样方便内部其他方法引用,但造成代码污染 | |
| // 例子之一 | |
| var app; | |
| app = (function(){ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| LIBRARY = Library.new | |
| def add_game(name, &block) | |
| game = Game.new(name) | |
| game.instance_eval(&block) | |
| LIBRARY.add_game(game) | |
| end | |
| def with_game(name, &block) | |
| game = LIBRARY.find_by_name(name) |