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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:06:00+00:00 2026-05-28T07:06:00+00:00

I have a relatively simple Backbone handled message container. I can add messages, and

  • 0

I have a relatively simple Backbone handled message container. I can add messages, and they display fine, but adding a delay to close them automatically does not work as undefined is passed on to the callback.

Could someone tell me how to properly specify the argument to be called? The main line is _.delay(function(){ messages.remove(this.model) }, 3000);

var Message = Backbone.Model.extend({
    defaults: {
        message: 'No message',
        type: 'error'
    },

    /*validate: function( attrs ) {
        if ( !attrs.type in ['error', 'warning', 'success', 'info'] ) {
            return 'Wrong message type given';
        }
    }*/
});
var Messages = Backbone.Collection.extend({
    model: Message
}) 
var messages = new Messages;

var MessageView = Backbone.View.extend({
    template: Handlebars.compile( $('#t-message').html() ),

    initialize: function() {
        messages.bind('delete', this.remove, this);
    },

    render: function( event ) {
        $(this.el).html( this.template( this.model.toJSON() ) );
        // TODO: this never fires properly
        _.delay(function(){ messages.remove(this.model) }, 3000);
        return this;
    }

});

var MessageContainerView = Backbone.View.extend({
    id: 'messages',
    initialize: function() {
        messages.bind('add', this.addMessage, this);
    },
    render: function( event ) {
        return this;
    },
    addMessage: function( message ) {
        var view = new MessageView({model: message});
        $('#' + this.id).append(view.render().el);
    }
});

var messagecontainerview = new MessageContainerView;
messages.add(new Message({message: 'Close this in 3 secs.', type: 'success'}))

Of course this.model is defined inside the render method, but it’s undefined in the remove call.

  • 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-05-28T07:06:01+00:00Added an answer on May 28, 2026 at 7:06 am

    It’s because this is bound to whatever is calling the delay callback function, not the view. Before you call _.delay assign var self=this; Then use self.model in the callback function.

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

Sidebar

Related Questions

I have a relatively simple (I think) use-case but I can't find any examples
I have a relatively simple query joining two tables. The Where criteria can be
I have what i thought was a relatively simple question but i cannot find
This should have been a relatively simple one but I must be making a
I have a relatively simple question. Say I have a file but I only
I have a relatively simple service that takes in a Message contract for uploading
I have what should be a relatively simple question that I can't seem to
I know this must be relatively simple, but I have a dataset of JSON
I have a relatively simple site that I'm working up for an intranet environment.
We have are relatively simple Reporting Services report that our users commonly export 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.