0

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

5
  • Well one that pops to mind is that jQuery would be a dependency of the former, and it wouldn't with the latter :) Commented Feb 28, 2013 at 18:10
  • 1
    This is not an appropriate question for SO. Commented Feb 28, 2013 at 18:11
  • Jon I revised my question Commented Feb 28, 2013 at 18:22
  • JavaScript isn't a design pattern, it's a language and you should learn it before even thinking about touching a library / framework. Commented Feb 28, 2013 at 18:25
  • Yes I know, I just have concern about the approach in using jquery plugin every where. Commented Feb 28, 2013 at 18:26

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.