Skip to content

Instantly share code, notes, and snippets.

@andreyfedoseev
Created March 2, 2012 04:59
Show Gist options
  • Save andreyfedoseev/1955809 to your computer and use it in GitHub Desktop.
Save andreyfedoseev/1955809 to your computer and use it in GitHub Desktop.
Boilerplate for jQuery plugin in CoffeeScript
class Widget
constructor: (@widget)->
@input.data("example-widget", @)
return
(($)->
$.fn.exampleWidget = (action, arg)->
@.each(->
$this = $(@)
widget = $this.data("example-widget")
if not widget
widget = new Widget($this)
if action
widget[action](arg)
)
)(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment