作者:摄影爱好者Summer_100 | 来源:互联网 | 2023-07-24 12:28
Iwasrecentlylisteningtoapodcastwhichmadeacommentonusing$()vsusingjQuery().Itwasst
I was recently listening to a podcast which made a comment on using $()
vs using jQuery()
. It was stated that every time $()
was used a new object would be created and when jQuery()
was used this was not the case. I google'd around but couldn't find anything on this specific topic.
我最近在收听一个播客,该播客对使用$()vs jQuery()进行了评论。据说,每次使用$()时都会创建一个新对象,当使用jQuery()时,情况并非如此。我谷歌了,但在这个特定主题上找不到任何东西。
I realize this is not a typical example, but the following is the reason I am interested in the answer to this question.
我意识到这不是一个典型的例子,但以下是我对这个问题的答案感兴趣的原因。
I have a page that the user will keep loaded in a browser for a whole day (24 hours, or possibly longer) and updates are done to the DOM every ~5 seconds as the result of an AJAX call via jQuery (the AJAX call portion is irrelevant to updating the DOM - the update to the DOM is done using a string of HTML and a call on a jQuery object to .empty()
and then .html()
).
我有一个页面,用户将在浏览器中加载一整天(24小时,或可能更长),并且每隔约5秒对DOM进行一次更新,这是通过jQuery调用AJAX(AJAX调用部分)的结果与更新DOM无关 - 对DOM的更新是使用HTML字符串和jQuery对象调用.empty()然后调用.html())完成的。
Since hearing this, I subsequently switched all of the $()
calls to jQuery()
calls, but I would like to know:
Is using $()
vs using jQuery()
a bad practice? Is there a negligible difference between the two? Or is it actually noticeable on larger projects?
听到这个,我随后将所有$()调用切换到jQuery()调用,但我想知道:使用$()vs使用jQuery()是一种不好的做法吗?这两者之间的差异是微不足道的吗?或者它在大型项目中是否真的值得注意?
6 个解决方案