Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:20:10+00:00 2026-06-11T11:20:10+00:00

I am trying to learn Backbone js, and am having trouble understanding the difference

  • 0

I am trying to learn Backbone js, and am having trouble understanding the difference between the event bindings using the underscore library provided bindAll/bind functions and jQuery provided on function. Here is an example in Coffeescript:

class Raffler.Views.Entry extends Backbone.View
  template: JST['entries/entry']
  tagName: 'li'

  events:
    'click': 'showEntry'

  initialize: ->
    @model.on('change',@render,this)
    @model.on('highlight',@highlightWinner,this)

  showEntry: ->
    Backbone.history.navigate("entries/#{@model.get('id')}", true)

  highlightWinner: ->
    $('.winner').removeClass('highlight')
    @$('.winner').addClass('highlight')

  render: ->
    $(@el).html(@template(entry: @model))
    this

This is a snippet of code from Ryan Bate's RailsCasts' on Backbone.js

Seems to me that the same code can be written using the underscore bindAll and bind functions as follows:

class Raffler....
  ...
  initialize: ->
    _bindAll @, 'render', 'highlightWinner'
    @model.bind 'change',@render
    @model.bind 'highlight',@highlightWinner
  ...

Questions:

  1. Are these two functionally equivalent?
  2. If yes then the jQuery code seems a lot clearer and more explicit. Is this just a matter of personal preference?

Thanks in advance for your time.

Bharat

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:20:12+00:00Added an answer on June 11, 2026 at 11:20 am

    jQuery’s “on” is used for a completely different purpose than Backbone’s “bind/bindAll”. The purpose of jQuery’s “on” is to call a function when an event occurs. The purpose of Underscore’s bind or bindAll is to bind a function to an object, meaning that whenever the function is called, the value of this will be the object you passed when calling bind. Underscore’s bindAll does the exact same thing as bind except with multiple functions at once.

    You’ll find that these will be used together when building with Backbone. Lets say you have a model set up with a function which you call internally to modify the model. If you used jQuery’s or Backbone’s “on” function to bind that function to an event, when the event it triggered, this will be the DOM element which triggered the event meaning any references to this in that function will no longer work because this is not a model any more, it’s a dom element. However, if we were to call _.bind(this, callback) in the constructor of the model, it would ensure that this is always the model.

    Backbone also implements an “on” function which is more similar to jQuery’s “on”, but used for Backbone events. It can be read about on the backbone docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn Backbone.js with Underscore.js and got into trouble. I'm using Grails
I was trying to learn the ways of testing Backbone-based app using Jasmine. For
I'm trying to learn Backbone.js and I seem to be having an issue with
im trying to learn delegates and events in c#, i understand that an event
I am trying to learn both Rails and Backbone.js at the same time. I
I was trying learn lex and yacc using the oreilly book. I tried following
Trying to learn F# but got confused when trying to distinguish between fold and
I'm a rails developer trying to learn Backbone and then I ran into this
trying to learn some html/css and I'm having a problem with fixed position divs.
Im trying to learn Android graphics & event handeling for a multiplayer game. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.