Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is jQuery18007779947370290756

Tags:

jquery

I use jQuery in my page, when I use Chrome developer tool, I found jQuery18007779947370290756 and jQuery object in Console. jQuery18007779947370290756 only contains a few methods. jQuery contains a lot more methods. so what is jQuery18007779947370290756 ? I do not have the url of the page, since it is internal page. the lib I include is just jquery-1.8.0.min.js and jquery-ui-1.8.23 and no JSONP calls.

It looks like if I added a global event 'beforeunload' to window object. and it is stored in window[expando]. However if I added some events to other DOM object such as button, and they are stored in jQuery.cache. here is the screen shot form jQuery.cache and window[jQuery1800xxxxxxxxxxxxxxxx] I am not sure why the guid for that 2 click events are both 8. those 2 click events are binded to 2 buttons. and click event handler are the same function.

enter image description here

like image 402
huahua Avatar asked Dec 07 '12 19:12

huahua


People also ask

What does $( this mean in jQuery?

$(this) is a jQuery wrapper around that element that enables usage of jQuery methods. jQuery calls the callback using apply() to bind this . Calling jQuery a second time (which is a mistake) on the result of $(this) returns an new jQuery object based on the same selector as the first one.

What is $$ in jQuery?

$$ has no significance to jQuery; its use is an arbitrary decision by whomever authored whatever it is your looking at.

What is $() in JavaScript?

$() The $() function is shorthand for the getElementByID method, which, as noted above, returns the ID of a specific element of an HTML DOM. It's frequently used for manipulating elements in a document. $() allows for shorter and more efficient JavaScript coding.

What is the main function of jQuery?

The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.


1 Answers

jQuery adds this property to elements when you store data on them. As this property is on the window element, somewhere in your code you're doing something equivalent to:

$(window).data('something', 1);

Note that jQuery events also uses the data module behind the scenes, so this could also be because you're adding an event to the window object.

For normal nodes (i.e. elements with a nodeType property), this value is set to a GUID (data.js#61), and the data you want to store on that object is stored in a global jQuery cache.

However the window element does not have a nodeType property, so it goes down the route of I'm a plain JS object; which leads the data to be stored directly on the object itself (which, in the case of window, may be a bug with jQuery).

The choice of cache location (global or on the object) is made in L39-45 in data.js:

// We have to handle DOM nodes and JS objects differently because IE6-7
// can't GC object references properly across the DOM-JS boundary
isNode = elem.nodeType,

// Only DOM nodes need the global jQuery cache; JS object data is
// attached directly to the object so GC can occur automatically
cache = isNode ? jQuery.cache : elem,

In the case of normal DOM elements, the value is assigned a GUID in data.js#61:

elem[ internalKey ] = id = jQuery.deletedIds.pop() || jQuery.guid++;

But in the case of normal JS objects (and window in this case), the object is built in 68 - 74:

cache[id] = {};

// Avoids exposing jQuery metadata on plain JS objects when the object
// is serialized using JSON.stringify
if (!isNode) {
    cache[id].toJSON = jQuery.noop;
}​

The weird value is jQuery.expando, which is defined in data.js#14, and is initialized to:

"jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" )

(basically, "jQuery", followed by the jQuery version with "."'s removed (1800 in your case), and then a random number).

like image 72
Matt Avatar answered Nov 13 '22 16:11

Matt