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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:37:01+00:00 2026-05-16T20:37:01+00:00

this is my demo code : <body onload=initialize()> <script> function initialize(){ var d=’adddd’ $.getScript(‘other.js’,

  • 0

this is my demo code :

<body onload="initialize()">

<script>
function initialize(){
    var d='adddd'
    $.getScript('other.js', function() {
        a()
    });
}   
</script>
</body>

and this is the demo other.js :

function a(){
    alert(d)
}

then , you will be find a error :

d is not defined

so you have to do this :

function a(d){
        alert(d)
    }

and

a(d)

if we have many Variable,we have to add them one by one , like this:

a(d,e,f,r,f,g,,h,e,w)

that is my Nightmare, so how to load another js file not use to add them ,

the next is my original code :

    <script type="text/javascript">
        function initialize() {
            var n=0;
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions = {
              zoom: 8,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"),
                myOptions);
            $.getScript('_lib/node.js', function() {
                console.log(node)
                var a = new node($('#test'),true);
                var b = new node($('#tabs_'));
            });

        }
    </script>

the node.js is :

    function node(obj,is_add_class_name) {
        this.n=0;
        this.setMap(map);
        this.obj=obj;

        this.is_add_class_name=is_add_class_name;
        var me=this;
        $('.delete').click(function(){
            if($('.delete',me.div_)[0]==this){
                me.onRemove()
            }
        })
        map.setOptions({
            draggable:true
        })
    }
    node.prototype = new google.maps.OverlayView();
    node.prototype.onAdd = function() {
        var div = $(this.obj)
        div.show();
        this.div_ = div[0];
        this.addPolygon(new google.maps.LatLng(-34.397, 150.644));
        var panes = this.getPanes();
        panes.overlayLayer.appendChild(div[0]);
    }
    node.prototype.onRemove = function() {
        this.div_.parentNode.removeChild(this.div_);
        this.div_ = null;
    }

but the error is :

map is not defined

the node.js is separated from the main document ,now i have to call node function use this :

var a = new node($('#test'),true,map,..other variables in main file );

that is very Complex, so my question is how to load a js file simply ,don’t use to
send every variables the js needed .

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-05-16T20:37:02+00:00Added an answer on May 16, 2026 at 8:37 pm

    What you seem to be wanting are global variables. These are usually frowned upon because their use can cause severe problems.

    In JavaScript if you declare your variables outside a function they are global and are accessible by any other script.

    So your sample code would be:

    <body onload="initialize()">
    
    <script>
    var d='adddd';
    function initialize(){
        $.getScript('other.js', function() {
            a()
        });
    }   
    </script>
    </body>
    

    Where I have simply moved the declaration of d outside the function so that it can be referenced by any other script.

    So why is this considered bad practice? Well, if you are combining many scripts from different sources and each one declares its own global variables, then there is no way to ensure that they do not step on each other. Further JavaScript has its own global variables which if you step over will result in difficult to find bugs.

    If you must use globals, then give them a name which indicates in which script they are defined, e.g. script1_d in your example. That way you make sure that globals have unique names and you know which one you are referencing.

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

Sidebar

Related Questions

This demo code loops 3 times and every time appends text. What I need
I ran the code to create the generically related objects from this demo: http://www.djangoproject.com/documentation/models/generic_relations/
I'm working on a demo about collision detection. (Some of the code for this
This is a really strange behavior, and I've set up some demo code to
Why does this code (taken from the demo sample at jquery ui), doesn't work
see this link...: Exemple on this site i have this code <body> <div id=geral>
look the demo code: class A def method_a puts this is method_a end end
Ok, I've got this code: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1> <script type=text/javascript href=https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js></script>
This is my code posted in a jsfiddle Demo. As you can see when
How to use this code (from the demo ) if the form isn't created

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.