Skip to content

Instantly share code, notes, and snippets.

@shallwelin
shallwelin / module.js
Last active December 14, 2015 00:49 — forked from guilhermepontes/module-es2015.js
JavaScript: module
// 本例是与 NewsWidget 的例子做个对比,以下的代码更科学,对于少用全局变量起到保护作用
// NewsWidget 的链接: http://css-tricks.com/how-do-you-structure-javascript-the-module-pattern-edition/
// NewsWidget 的例子,把全局变量 s 作为指向 NewsWidget对象的内部设置,这样方便内部其他方法引用,但造成代码污染
// 例子之一
var app;
app = (function(){
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>
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)