何时使用Vanilla JavaScript与jQuery? - When to use Vanilla JavaScript vs. jQuery?

问题:

I have noticed while monitoring/attempting to answer common jQuery questions, that there are certain practices using javascript, instead of jQuery, that actually enable you to write less and do ... well the same amount. 我注意到在监控/尝试回答常见的jQuery问题时,有一些使用javascript而不是jQuery的实践,实际上可以让你写得更少,并做 ...相同的数量。 And may also yield performance benefits. 并且还可以产生性能优势。

A specific example 一个具体的例子

$(this) vs this $(this) vs this

Inside a click event referencing the clicked objects id 在单击事件中引用单击的对象id

jQuery jQuery的

$(this).attr("id");

Javascript 使用Javascript

this.id;

Are there any other common practices like this? 还有其他类似的常见做法吗? Where certain Javascript operations could be accomplished easier, without bringing jQuery into the mix. 可以更轻松地完成某些Javascript操作,而无需将jQuery添加到组合中。 Or is this a rare case? 或者这是一个罕见的情况? (of a jQuery "shortcut" actually requiring more code) (jQuery“快捷方式”实际上需要更多代码)

EDIT : While I appreciate the answers regarding jQuery vs. plain javascript performance, I am actually looking for much more quantitative answers. 编辑:虽然我很欣赏有关jQuery与普通javascript性能的答案,但实际上我正在寻找更多的定量答案。 While using jQuery , instances where one would actually be better off (readability/compactness) to use plain javascript instead of using $() . 在使用jQuery时 ,使用普通javascript代替使用$()实际上会更好(可读性/紧凑性)的实例。 In addition to the example I gave in my original question. 除了我在原始问题中给出的例子。


解决方案:

参考一: https://stackoom.com/question/JWB1
参考二: When to use Vanilla JavaScript vs. jQuery?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章