Created
July 13, 2012 02:43
-
-
Save DyegoCosta/3102364 to your computer and use it in GitHub Desktop.
CoffeeScript namespacing
This file contains 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
namespace = (target, name, block) -> | |
[target, name, block] = [exports ? window, arguments...] if arguments.length < 3 | |
top = target | |
target = target[item] or= {} for item in name.split '.' | |
block target, top | |
class Foo | |
constructor: (@message) -> | |
Bar: -> | |
alert @message | |
namespace "Coffee", (exports) -> | |
exports.Foo = Foo |
This file contains 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
$('#start').click -> | |
foo = new Coffee.Foo "Test!" | |
foo.Bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment