my goal is to create a sort of "Javascript library," if you could call it that. I'm intending to use it to just manipulate pages as I browse the web, dynamically loading it as a greasemonkey script. The idea is to have "win" get mapped to window, "doc" -> document, "win.loc" -> win.location, and a few other convenience mappings, but you get the idea. Can you just give me a few examples for me to pick up the syntax from, and I'll extrapolate the rest? Thanks so much.
Just assign variables like so:
var win = window;
var doc = document;
You can't assign win.loc without modifying the window object in this case though. Also, the window object is special because after assigning win, you'll be able to get it with win.win or win.win.win and so on (window is the global object.)
In any case, you can still assign loc to the window object:
win.loc = window.location;
// Can now be referenced as:
loc; // (window is the global object)
win.loc;
win.location;
window.location;
Now that is how to do what you're asking for. Most likely you shouldn't do this. Normally, frameworks are defined to use up only one global variable, with a suitable name:
var Blixt = (function () {
var localVariable = 123;
return {
loc: window.location,
myFunc: function () {
alert(localVariable);
}
};
})();
All this is pretty complex stuff if you're not familiar with JavaScript though, so it's not a good project to start with if you're new to JavaScript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With