Reputation: 11637
I have an interesting problem that I'm unsure how best to solve.
I have JS scripts which contain the following:
var obj = new namespace.MyObjectName("key", [12, 11, 22, 33, 454, 552, 222], [33, 22, 33, 11, 22, 222, 111]);
namespace.MyObjectName = function(keyName, data1, data2) {
this.myData1 = data1;
this.myData2 = data2;
this.holder = [
[keyName, [myData1, myData2]]
];
};
namespace.MyObjectName.prototype.DoSomething = function(arg1, argArray) {
this.globalVar = [
"Display " + arg1 + " into string using " + argArray[0] + "<br> for visual purposes",
"Display " + arg1 + " into string using " + argArray[2] + "<br> for visual purposes"
];
};
Automation is creating copies of these JS files, each containing the same declaration of the object as per above, with filenames along the lines of:
The per file difference is that the DoSomething method name contents are always different/generated, as are the array values passed to the constructor.
All of the above was just fine during the life of that JS being used standalone.
Here are some options I am considering:
My current bias is towards (1) but I'm putting the whole thing out for discussion since that approach might have inherent problems or others may be clearly demonstrated as superior.
Upvotes: 0
Views: 661
Reputation: 29267
I dont really understand the problem, but to avoid the trampling of the namespace you could do:
var namespace = namespace || function() {}
Upvotes: 0
Reputation: 10422
Regarding (2), it's possible to run javascript in a sandbox by using an iframe, check out for instance Dean Edwards' Sandbox.eval() or the Slickspeed Selectors Test.
Upvotes: 1