Skip to content

Instantly share code, notes, and snippets.

@aTei
Last active December 19, 2015 02:28
Show Gist options
  • Save aTei/5883033 to your computer and use it in GitHub Desktop.
Save aTei/5883033 to your computer and use it in GitHub Desktop.
jQuery plugin as CoffeeScript class template
class PluginClass
constructor: (@target) ->
_this = @ # to access Class inside @target.each and not modificate @ inside @target.each
eventData = {_class: _this} # to access Class inside event handlers
@target.each ->
self = $(@)
self.on 'click', eventData, _this.submitHandler
submitHandler: (e)->
_this = e.data._classs
e.preventDefault()
console.log 'Working!'
$.fn.plugin = ->
new PluginClass this
this
$('a').plugin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment