jQuery variable name appended with a large number

2019-08-06 02:14发布

I often see in my code I am loading from my company's media central that jQuery is not available in the console normally. (No $ and jQuery)

But sometimes, to those elements to which jQuery is attached, it has a long number with it.

jQuery18306575689211022109_1378907534666

What is the purpose of doing this? Security?

Also, jQuery is sometimes available directly in the console, but only with the above numbers. I am therefore unable to debug my apps in console, where I need to query using jQuery.

However, in the JavaScript code, jQuery is perfectly being used as $ and jQuery. So I apply a break-point and export as window.jQuery = jQuery.

Is this a proper way to debug the app, when jQuery is obfuscated?

UPDATE:

For eg., check this URL the app is calling. It seems that the URL knows what is the number appended to jQuery. How do I come to know of the same number while debugging? Any lights on what is going on?

2条回答
Deceive 欺骗
2楼-- · 2019-08-06 02:43

It's a callback id automatically generated by jQuery. See the documentation for jsonpCallback.

It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling.

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-06 02:47

It seems that you are confusing two different variables. You can make a quick test on this website : http://www.jquery4u.com/function-demos/jsonp/#demo. Click "run demo", open Chrome's console, type "jQuery" in order to retrieve the callback's name, then perform this simple comparison :

jQuery16409391013463027775_1379048051365 === jQuery // false

That said, the fact that the variables named "$" and "jQuery" are not available in your case may be due to a specific implementation. One possibility could be the use of jQuery.noConflict() which allows either to customize the name used as a reference to jQuery, or to completely remove all references to jQuery from the global scope (window), so there is no way to access it in the console.

查看更多
登录 后发表回答