Skip to content

Instantly share code, notes, and snippets.

@jonathandean
Created June 19, 2013 20:11
Show Gist options
  • Save jonathandean/5817623 to your computer and use it in GitHub Desktop.
Save jonathandean/5817623 to your computer and use it in GitHub Desktop.
Generic objects in CoffeeScript
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()
@jonathandean
Copy link
Author

internally get to options using opts.some_option

@jonathandean
Copy link
Author

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