Created
June 18, 2011 22:33
-
-
Save caseyohara/1033568 to your computer and use it in GitHub Desktop.
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
var Application = { // the module, a static wrapper | |
FXSPEED : 500, // a constant (sort of) | |
user : { // a nested static object | |
id : 123 | |
}, | |
toggle : function(){ ... }, // a static method | |
Interface : function(){ // a class | |
this.initialize = function(){ | |
this.active = true; | |
this.build(); | |
return this; | |
} | |
this.build = function(){ | |
... | |
} | |
this.doSomething = function(){ | |
return "did something"; | |
} | |
return this.initialize(); | |
} | |
} |
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
# application/interface.rb | |
module Application | |
class Interface | |
attr_accessor :active | |
def initialize | |
@acitve = true | |
build | |
end | |
def build | |
... | |
end | |
def do_something | |
'did something' | |
end | |
end | |
end |
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
class Animal | |
constructor: (@name) -> | |
move: (meters) -> | |
alert @name + " moved " + meters + "m." | |
class Snake extends Animal | |
move: -> | |
alert "Slithering..." | |
super 5 | |
class Horse extends Animal | |
move: -> | |
alert "Galloping..." | |
super 45 | |
sam = new Snake "Sammy the Python" | |
tom = new Horse "Tommy the Palomino" | |
sam.move() | |
tom.move() |
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
Application.active // true | |
Application.user.id // 123 | |
var interface = new Application.Interface() | |
interface.doSomething() // 'did something' |
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
└── scripts | |
|── application.js | |
├── application | |
├── controller.js | |
├── data.js | |
└── interface.js |
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
// scripts/application.js | |
// creates the wrapper module and contains all static members | |
var Application = Application || { | |
FXSPEED : 500, | |
user : { | |
id : 123 | |
}, | |
toggle : function(){ ... }, | |
} |
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
// scripts/application/interface.js | |
Application.Interface = function(){ | |
this.initialize = function(){ | |
this.active = true; | |
this.build(); | |
return this; | |
} | |
this.build = function(){ | |
... | |
} | |
this.doSomething = function(){ | |
return "did something"; | |
} | |
return this.initialize(); | |
} |
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
// scripts/application/controller.js | |
Application.Controller = function(){ | |
... | |
} |
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
└── lib | |
|── application.rb | |
├── application | |
└── interface.rb |
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
# application.rb | |
module Application | |
FXSPEED = 500 | |
def user | |
{ 'id' => 123 } | |
end | |
def toggle | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment