Javascript aliases

My goal is to create a kind of "Javascript library", so to speak. I intend to use it to simply manipulate pages when I browse web pages, dynamically loading them as a greasemonkey script. The idea is to have " win" displayed on window, " doc" → document, " win.loc" → win.locationand a few other handy mappings, but you get the idea. Can you just give me some examples for me to get the syntax and I will extrapolate the rest? Many thanks.

+3
source share
2 answers

Just assign such variables:

var win = window;
var doc = document;

win.loc, window. , , win win.win win.win.win .. (window - .)

loc window:

win.loc = window.location;

// Can now be referenced as:
loc; // (window is the global object)
win.loc;
win.location;
window.location;

, . , . , :

var Blixt = (function () {
    var localVariable = 123;

    return {
        loc: window.location,
        myFunc: function () {
            alert(localVariable);
        }
    };
})();

, JavaScript, , JavaScript.

+11

** : ** Blixt, .

, - . :

  • , win.loc , window.location - ? ( )

  • , Blixt . / ?

  • JS, ? ? - C-l javascript:win.loc=doc.ref<ENTER> , CTRL, , .

  • , , , - URI js: javascript: ? .

0

Source: https://habr.com/ru/post/1711296/


All Articles