Jquery plugin Vs javascript

纵饮孤独 提交于 2019-12-25 05:02:55

问题


Can somebody please explain the pros and cons for below.

Am having a function to get the url querystring parameters, but I need to know which is the best way to write the function. Eg: if i create the function using jquery plugin style, then every time I need to use a target element to access the function as below

$("#targetDom").getQueryString("name");

However, if I create the function using javascript classes or javascript design pattern, it would be

getQueryString("name");

This is a small example but considering large application which approach is best? is there any disadvantage in going with jquery plugin way?

Regards,

Navin


回答1:


I found a while ago this sentence:

Don't learn jQuery. Just use it.

It's one of the best advices for a newbie, I think.

jQuery is just an addition to javascript. It simplifies DOM traversing/manipulation, makes easy event handling and so on, but it is not something you should start learning before you know vanilla Javascript.

Regarding your example, it is not the best thought example for jQuery plugin.

The syntax you suggested ($("#targetDom").getQueryString("name");) implies that you treat URL query string as attached somehow to the HTML element, which is wrong...



来源:https://stackoverflow.com/questions/15142574/jquery-plugin-vs-javascript

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