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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:09:33+00:00 2026-05-30T10:09:33+00:00

So, first question I couldn’t find an answer to. Might be reason enough to

  • 0

So, first question I couldn’t find an answer to. Might be reason enough to ask my own first question. Apologies if the answer can be found outside the scope of backbone.js.

In a backbone.js app, I need to have access to several variables in different functions, so I have to use some global variables setup.

I’m wondering if my current solution is acceptable/good practise. My IDE (IDEA) seems to think it isn’t:

var MyModel = Backbone.Model.extend({

initialize:function(){
  var myGlobalVar, myOtherGlobalVar;//marked as unused local variable
},

myFunction:function() {          
      myGlobalVar = value;//marked as implicitly declared
      model.set({"mrJson": {"email": myGlobalVar}});
      model.save();
    });
  }
},

myOtherFunction:function() {          
      myOtherGlobalVar = otherValue;//marked as implicitly declared
      model.set({"mrJson": {"email": myGlobalVar, "other": myOtherGlobalVar}});
      model.save();
    });
  }
}
}

I tried declaring the implicitly declared globals, but that resulted in them not being accessible from the othe function.

Is there a proper way to do handle these global variables in backbone.js?

  • 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-30T10:09:35+00:00Added an answer on May 30, 2026 at 10:09 am

    The way you are currently declaring the variables, they are in the function initialize scope, rather than then object MyModel scope. To define the variables as Model variables (accessible to all object functions) do:

    var MyModel = Backbone.Model.extend({
    
    myGlobalVar: null,
    myOtherGlobalVar: null,
    
    initialize:function(){
      console.log(this.myGlobalVar)
    },
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, apologies if this question has been asked before but I couldn't find
I have been looking around for an answer to my question but couldn't find
After prepairing an answer for this question I found I couldn't verify my answer.
Silly question but couldn't find the right answer on Google (or didn't know what
First of all, apologies for the title of this question, but i couldn't come
When submitting an answer I get this error: ActiveRecord::RecordNotFound (Couldn't find Question with ID=answer):
possibly a simple question, but I couldn't find definitive answer (see below for excerpt
I was just curious about the question, but couldn't find the answer in the
First question is, given a url to an mp4 video, how can I save
(First question related to iPhone development, so apologies for sounding off-track.) I'm creating a

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.