Created
June 19, 2013 20:11
-
-
Save jonathandean/5817623 to your computer and use it in GitHub Desktop.
Generic objects in CoffeeScript
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 = NameSpace or {} | |
NameSpace.ClassName = (options) -> | |
# default options | |
defaultOpts = -> | |
defaultOpts:: = | |
some_option: "some value", | |
another_option: "another value" | |
# private vars | |
self = this | |
opts = $.extend({}, new defaultOpts(), options) | |
# private methods | |
something = -> | |
# method code | |
# public methods | |
self.init = -> | |
# init code | |
return | |
window.instance = new NameSpace.ClassName() | |
$ -> | |
window.instance.init() |
this version doesn't pass in options but you'd overwrite the default with: window.instance = new NameSpace.ClassName({ some_value: "something else" })
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
internally get to options using
opts.some_option