Skip to content

Instantly share code, notes, and snippets.

@meleyal
Created June 18, 2012 10:45
Show Gist options
  • Save meleyal/2947837 to your computer and use it in GitHub Desktop.
Save meleyal/2947837 to your computer and use it in GitHub Desktop.
Backbone Bridge v2
Backbone.View.bridge = (klass, namespace = window) ->
name = klass.charAt(0).toLowerCase() + klass.slice(1)
return unless namespace[klass]
console.log $.fn[name]
return $.fn[name] if $.fn[name]?
$.fn[name] = (options = {}) ->
$el = $(this)
opts = _.extend(options, { el: this })
ctor = new namespace[klass] opts
data = $el.data(name)
$el.data(name, ctor) unless data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment