-2

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?

6
  • May I ask why you aren't using one of the numerous plugins / functions already available to do this? See this post for tons of options. Also, you don't need a selector to use a jQuery plugin, you could extend it and use $.fn.getQueryString("name"); (for example). Commented Feb 28, 2013 at 18:38
  • 1
    duplicate of Jquery plugin Vs javascript - which was closed because this is a question without a specific and definite answer, and thus is not suitable for StackOverflow. Commented Feb 28, 2013 at 18:39
  • Write a jQuery plugin when you specifically want to do something with jQuery collections. Commented Feb 28, 2013 at 18:40
  • @Madbreaks Because there is no definite answer. It is not constructive: As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance. Commented Feb 28, 2013 at 18:42
  • @bažmegakapa am not sure why this is not constructive, because this a question from a developer with real time situation, is this community not help developers each other ? Commented Feb 28, 2013 at 18:46

2 Answers 2

2

The answer will depend on who you ask.

My answer is, if you're already using jQuery on your page (meaning leveraging jQuery won't require you to import additional resources) then go ahead and use jQuery to write your extension. jQuery does internal chaching which I believe can actually make your code faster than using native JavaScript in some cases.

If you're not already using jQuery, using vanilla JavaScript for your particular task isn't complex enough a problem to require (or even suggest you might want to use) jQuery.

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

Comments

1

You don't have to create a jQuery function for every functionality, especially if you are not going to be dealing with the DOM, which seems to be your case.


However, you might want to group such functions in a small library of your own application, which can be reused in other applications as well.

For example:

var utils = {
    getQueryString : function(name){}
};

and access it like this...

utils.getQueryString("name");

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

No, you don't. You can run the function like this as well $.fn.getQueryString("name");.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.