I have a JavaScript file: "myCode.js"
This file contains some javascript code:
var user = JSON.parse(localStorage.getItem("m"));
d.Stacks.Set.Map = user.layer;
d.Provider = user.Provider;
var s = user.Stacks;
if (s instanceof Array){
d.geo.ref = user.stacks.name;
} else {
d.geo.ref = user.stacks.name;
}
This code is not in any function.
I have multiple files that use this code and instead of copying and pasting this code into every page i want a way to e.g. make a link to this "myCode.js" and call the code. The other files all have functions which require this piece of code.
e.g
var d = $.getJSON("main.json", function(d) {
var user = JSON.parse(localStorage.getItem("m"));
d.Stacks.Set.Map = user.layer;
d.Provider = user.Provider;
var s = user.Stacks;
if (s instanceof Array){
d.geo.ref = user.stacks.name;
} else {
d.geo.ref = user.stacks.name;
}
o.load(d);
});
what i want to have is:
var d = $.getJSON("main.json", function(d) {
//HAVE THE CODE FROM "myCode.js" here
o.load(d);
});
Is this possible? if yes, how? :) Thanks in advance.