Skip to content

Instantly share code, notes, and snippets.

@caseyohara
Created June 18, 2011 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseyohara/1033568 to your computer and use it in GitHub Desktop.
Save caseyohara/1033568 to your computer and use it in GitHub Desktop.
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();
}
}
# 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
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()
Application.active // true
Application.user.id // 123
var interface = new Application.Interface()
interface.doSomething() // 'did something'
└── scripts
|── application.js
├── application
   ├── controller.js
    ├── data.js
   └── interface.js
// scripts/application.js
// creates the wrapper module and contains all static members
var Application = Application || {
FXSPEED : 500,
user : {
id : 123
},
toggle : function(){ ... },
}
// 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();
}
// scripts/application/controller.js
Application.Controller = function(){
...
}
└── lib
|── application.rb
├── application
   └── interface.rb
# 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