I have a XSL template that uses a miniaturized javascript file J1. It can be assumed that J1 is impossible to trace and reverse engineer.
The problem I have is that there is a slightly more updated version of J1 (called J1a) and I am interested to use J1 for some parts of the code and J1a for other parts of the code in the same template. Obviously, including both in the same file will be problematic due to duplicate classes and functions. I’ve tried to no avail to wrap either J1 or J1a into a pseudo-namespace (Javascript does not support namespaces or modules) with the following code:
function mynamespace() {
this.container = {
// insert monstrous javascript blob
}
} // which then is expected to do sth like mynamespace.Container.SomeFunction()
I’ve also tried a dirty refactor by just manually renaming a gazillion names (which is very error-prone), but neither approach work.
During the writing of this post, I’ve thought of a third approach, which is to add a function X() in J1 and a function Y() in J1a and then delegate my tasks to those wrapper functions which should solve the problem due to the fact that J1 and J1a do not import each other. However, I’ve not tested this and I am not an experienced javascript writer.
Edit:
Since all I really need from J1 and J1a is the following:
MyObject.SomeStaticMethod();
MyObject obj = new MyObject(args);
obj.SomeInstanceMethod();
then maybe I can do:
function X(var args) {
MyObject.SomeStaticMethod();
MyObject obj = new MyObject(args);
obj.SomeInstanceMethod();
}
function Y(var args) {
MyObject.SomeStaticMethod();
MyObject obj = new MyObject(args);
obj.SomeInstanceMethod();
}
and add X to J1 and Y to J1a and then call X() and Y() selectively in the XSL template?
Edit 2: It turns out the giant miniaturized javascript blob does not contain conventional global variables, but something that’s about as bad – variables tethered to the windows object.
With that said, is there any way to somehow split the rendering of the HTML so that one part only has one copy in the global scope and another part has the other copy in the global scope? I’ve heard there’s some “tile approach” with JSP. Frames is also a possibility, although I heard there’s a slew of problems with using them.
here’s a variant that mimics what node does.
then use
etc….
You also need to make sure your giant blob does not use any global variables.