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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:37:52+00:00 2026-06-05T17:37:52+00:00

var JavascriptHelper = Backbone.Model.extend(JavascriptHelper, {}, // never initialized as an instance { myFn: function()

  • 0
var JavascriptHelper = Backbone.Model.extend("JavascriptHelper",
        {}, // never initialized as an instance
        {
            myFn: function() {
                $('.selector').live('click', function() {
                    this.anotherFn(); // FAIL!
                });
            },

            anotherFn: function() {
                alert('This is never called from myFn()');
            }
        }
    );

The usual _.bindAll(this, ...) approach won’t work here because I am never initializing this model as an instance. Any ideas? Thanks.

  • 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-05T17:37:54+00:00Added an answer on June 5, 2026 at 5:37 pm

    You could do it by hand:

    myFn: function() {
        $('.selector').live('click', function() {
            JavascriptHelper.anotherFn();
        });
    }
    

    Or, if anotherFn doesn’t care what this is when it is called (or if it wants this to be what live uses):

    myFn: function() {
        $('.selector').live('click', JavascriptHelper.anotherFn);
    }
    

    As an aside, live has been deprecated in favor of on. Also, if you’re not instantiating your JavascriptHelper, then why is it a Backbone.Model at all? Why not use a simple object literal:

    var JavascriptHelper = {
        myFn: function() {
            //...
        },
        anotherFn: function() {
            //...
        }
    };
    

    And what are you expecting this construct:

    var JavascriptHelper = Backbone.Model.extend(string, {}, {...})
    

    to leave you in JavascriptHelper? Extending a string is strange but passing three arguments to Backbone.Model.extend is pointless, it only cares about two arguments. If you want static properties then you should be passing them as the second argument:

    var JavascriptHelper = Backbone.Model.extend({}, { myFn: ... });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var h=0; var w=0; $(.extend).hover(function() { //alert(h); $(this).css({'z-index' : '999' }); $(this).addClass(hover).filter(:not(:animated)).stop() .animate({ marginTop:
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var UI$Contract$ddlForm_change = function() { //'this' is currently the drop down that fires the
var A=function(){ }; $.extend(A.prototype, { init:function(){ alert('A init'); } }); var B=function(){ }; $.extend(B.prototype,A.prototype,{
var UsersMenu = function(){ this.returnUsers = []; this.retrieve = function(posts){ var temp = [];
var conversations = new Array(); jQuery('.CChatWindow').each(function(){ if (jQuery(this).is(:visible) && jQuery(this).attr(data-conversationid) != 0) { alert(jQuery(this).attr(data-conversationid));
var chart; var d = new Array(); function click() { d = document.getElementById('graph:hi').value; alert(d);
var plugin = { Init: function() { this.UpdateUI(); if (this.Status() == 1) { ...
var MyObj = function(h,w){ this.height = h; this.width = w; } I would like
var Gallery = Backbone.Controller.extend({ _index: null, _photos: null, _album :null, _subalbums:null, _subphotos:null, _data:null, _photosview:null,

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.