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 8811089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:16:36+00:00 2026-06-14T03:16:36+00:00

In my view class initialize function, _.bind(this.appendSection, this) does not work, but _.bindAll(this, ‘appendSection’)

  • 0

In my view class initialize function, _.bind(this.appendSection, this) does not work, but _.bindAll(this, 'appendSection') works. I am very confused…

Here is the code:

TemplateBuilder.Views.TemplateView = Backbone.View.extend({
        el: $('div#evalTemplate'),

        initialize: function(){
            this.collection.on('reset', this.render, this);
            //_.bind(this.appendSection, this);
            _.bindAll(this, 'appendSection');                
        },

        events: {
            'click button#addSection': 'addSection'
        },

        render: function(){
            this.collection.each(this.appendSection);
            return this;
        },

        appendSection: function(section){                
            var view = new TemplateBuilder.Views.InstructionView({model: section});
            this.$el.append(view.render().el);
        },

        addSection: function(){
            var newSection = new TemplateBuilder.Models.Section();                
            this.collection.add(newSection);
            this.appendSection(newSection);
        },
    });  
  • 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-14T03:16:37+00:00Added an answer on June 14, 2026 at 3:16 am

    From the fine manual:

    bind _.bind(function, object, [*arguments])

    Bind a function to an object, meaning that whenever the function is called, the value of this will be the object. […]

    var func = function(greeting){ return greeting + ': ' + this.name };
    func = _.bind(func, {name : 'moe'}, 'hi');
    func();
    => 'hi: moe'
    

    Unfortunately the manual isn’t quite so fine and you have to see what’s implied by the example code:

    func = _.bind(func, ...);
    

    _.bind returns the bound function, it doesn’t modify it in-place. You’d have to say this:

    this.appendSection = _.bind(this.appendSection, this);
    

    if you wanted to use _.bind. _.bindAll on the other hand, binds methods in place. There is more discussion on these methods over here.

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

Sidebar

Related Questions

The MSDN site says: From your view class's function that handles the WM_CREATE message
var ListView = Backbone.View.extend({ el: $('hello'), events: { 'click .myName': 'namefunc', }, initialize: function()
class AboutController extends Zend_Controller_Action { public function init() { /* Initialize action controller here
So I have a View that looks like this. //base class var SelectListView =
Im unable to initialize Jquery(Zendx) and View helpers in Bootstrap.php(ZF: 1.10.8) But Im able
I have the view class FoursquareSearch.Views.Origin extends Backbone.View events: 'change [name=origin]': 'setOrigin' 'click [name=geolocate]'
I have created a class which extends View class. public class SplashScreen extends View
I have these 2 methods in the View class. the drawRect method always gets
I've created a custom view class and right now just want to draw an
I'm creating an autolayout-friendly split view class for one of my applications. Among its

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.