Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

12/07/12: Off with the Backbone!

Sheel Choksi
Friday, December 7, 2012

Interestings

Backbone.off can unbind callbacks from all instances of a class instead of just the instance you want

If you set up some bindings such as

viewClass = Backbone.View.extend({...})
view1 = new viewClass();
view2 = new viewClass();
model.bind("event", view1.myFunction, view1)
model.bind("event", view2.myFunction, view2)

and then want to unbind one of the callbacks…

model.off("event", view1.myFunction)

you will unbind both callbacks. You need to use

model.off("event", view1.myFunction, view1)

This is fundamentally because of javascript prototypes that mean view1.myFunction == view2.myFunction

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Add New Comment Cancel reply

Your email address will not be published.

Sheel Choksi

Sheel Choksi
San Francisco

Recent Posts

  • 12/06/12: Prove your mohawk
Subscribe to Sheel's Feed

Author Topics

agile (2)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >