The window object summary

Local objects: independent of the host environment of ECMAScript implementation object provides. The most common local object has: Object, Function, Array, String, Boolean, Number The, a Date, RegExp, Error and so on.

Built-in objects: built-in objects you do not need to instantiate the main objects of Global and Math object;

Global objects: it is the most special ECMAScript objects, because in fact it does not exist, but they will be clear, in ECMAScript, independent function does not exist, all functions must be a method of an object. Similar to parseFloat (), parseInt (), escape (), unescape (), isFinite (), isNaN (), eval (), encodeURI () and encodeURIComponent (), it looks the function, in fact, they are It is a Global object.

window object: ECMAScript does not indicate how direct access to the Global object, but the browser is to be implemented as part of the Global Object window object. Therefore, all variables and functions at global declaration space, it has become the property of the window object.

Comparative Global Objects Window objects and

The Global object is any environment are present.

Functions and global functions window object is not the same. Global function does not belong to any built-in object.

With no inheritance, it can be considered the default browser provides the use of objects are placed in the Global object, and window objects also happens is this Global object. In fact, the internal implementation of the browser, hiding the true Global object, the window object as a substitute Global object. Global objects for all operations (indirect action), the window is mapped to an object, and vice versa. Such window object has become a substitute Global object. The window object is at the same time as an attribute of Global object. In this way, the true Global object is put on ice.

Practical application:

1. Encryption js, if you want to encrypt objects Global objects, you can register with the window in a special variable. E.g:

window['_ab'] = window['parseInt']
var a = _ab('234');
the console.log (A, 'Print');

This realization of a simple js encryption. Commonly used encryption in this manner may be used: Date, Math, parseInt, parseFloat, Array, etc.

 

2. encrypt js object methods. For example: getTime method

 window['_df'] = window['Date']
 window["_w3"] = 'getTime'
 var b = new _df()
 var c = b[_w3]()
the console.log (C, 'Print')

Or may utilize closure

window['_df'] = window['Date']
window["_w3"] = _vP('getTime')
 function _vP (_BT) {
        return function () {
            return _BT
        }
   }
 There are b = new _df ()
 has c = b [_w3 ()] ()
the console.log (C, 'Print')

Guess you like

Origin www.cnblogs.com/xuexia/p/12058641.html