jQuery variable name appended with a large number

笑着哭i 提交于 2020-01-25 06:32:04

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/18743371/jquery-variable-name-appended-with-a-large-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!