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