何時使用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?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章