Skip to content

Instantly share code, notes, and snippets.

@nickw
Forked from jimeh/jquery.myplugin.coffee
Created April 24, 2012 01:49
Show Gist options
  • Save nickw/2475462 to your computer and use it in GitHub Desktop.
Save nickw/2475462 to your computer and use it in GitHub Desktop.
Example jQuery plugin written in CoffeeScript, and the resulting compiled JavaScript file.
$.fn.extend
myplugin: (options) ->
self = $.fn.myplugin
opts = $.extend {}, self.defaultOptions, options
for el in this
self.init el, opts
self.log el if opts.log
$.extend $.fn.myplugin,
defaultOptions:
color: 'red'
log: true
init: (el, opts) ->
this.color el, opts
color: (el, opts) ->
$(el).css('color', opts.color)
log: (msg) ->
console.log msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment