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

  • SEARCH
  • Home
  • 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 7770347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:23:16+00:00 2026-06-01T16:23:16+00:00

Sort of a novice javascript person reading a backbone.js tutorial http://arturadib.com/hello-backbonejs/docs/5.html and have a

  • 0

Sort of a novice javascript person reading a backbone.js tutorial http://arturadib.com/hello-backbonejs/docs/5.html and have a few questions about some of the code the author uses.

In the initialize function below, the author binds

  this.model.bind('change', this.render);
  this.model.bind('remove', this.unrender);

I’m assuming this means the render function is called on the ‘this’ object whenever the change function is called, and unrenderis run whenever remove is called. The problem, for me, is that there is a defined function 'remove' in his code, but no defined function 'change'

Question: Do change and remove refer to jquery functions or does the remove function refer to the remove function defined in the code (i.e. it overrides the jquery function) while change refers to the jquery function. If the latter, what exactly triggers the 'change' function if it’s never explicitly called and, hence, the render function?

Code

var ItemView = Backbone.View.extend({
    tagName: 'li', // name of tag to be created        


    events: { 
      'click span.swap':  'swap',
      'click span.delete': 'remove'
    },    


    initialize: function(){
      _.bindAll(this, 'render', 'unrender', 'swap', 'remove'); // every function that uses 'this' as the current object should be in here

      this.model.bind('change', this.render);
      this.model.bind('remove', this.unrender);
    },


    render: function(){
      $(this.el).html('<span style="color:black;">'+this.model.get('part1')+' '+this.model.get('part2')+'</span> &nbsp; &nbsp; <span class="swap" style="font-family:sans-serif; color:blue; cursor:pointer;">[swap]</span> <span class="delete" style="cursor:pointer; color:red; font-family:sans-serif;">[delete]</span>');
      return this; // for chainable calls, like .render().el
    },


    unrender: function(){
      $(this.el).remove();
    },


    swap: function(){
      var swapped = {
        part1: this.model.get('part2'), 
        part2: this.model.get('part1')
      };
      this.model.set(swapped);
    },



    remove: function(){
      this.model.destroy();
    }
  });

​

  • 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-01T16:23:17+00:00Added an answer on June 1, 2026 at 4:23 pm

    The change and remove are Backbone events, not jQuery events. These:

    this.model.bind('change', this.render);
    this.model.bind('remove', this.unrender);
    

    mean that this.render will be called when the model triggers a change event and this.unrender will be called when the model triggers a remove event. The set method on models:

    set model.set(attributes, [options])

    Set a hash of attributes (one or many) on the model. If any of the attributes change the models state, a "change" event will be triggered, unless {silent: true} is passed as an option.

    is one way to trigger a model’s change event, unset and clear will also trigger change events.

    remove events generally come from collections but the collection will send them through the appropriate models in case there are views listening.

    You might want to read the (quite good) Backbone documentation and review the Catalog of Events in particular.

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

Sidebar

Related Questions

I apologize that I am very much a novice with javascript. I have sort
Im following a tutorial online (http://my.opera.com/learnror/blog/ldap-binding-and-authentication-ror) to setup authentication against an LDAp active directory
I often have to sort a dictionary (consisting of keys & values) by value.
I have a strange one (or at least it's beyond me as a novice
This is likely a novice question about LINQ, but assuming I have a set
I have an array of items as follows in Javascript: var users = Array();
I have the following code which takes a normal HTTP GET Request and returns
I am a git novice trying to sort through the concepts and terms. The
I m novice to Silverlight... I have created a usercontrol and want to consume
I'm a novice developer, some experience with rails but still have a lot to

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.