1

I am trying to write all my query code in an object oriented way. But I don't know how to implement this for each click function and hover function etc. I also wanted to know:

  1. What are the advantages of writing query in object oriented way?
  2. For query what is better the object oriented way or in the ordinary way?
1
  • Eek, please edit your question and remove the spaces at the beginning, this is hurting my eyes... Commented Jun 5, 2010 at 12:43

3 Answers 3

4

Two counter-questions, that may help you deciding how to proceed on this:

  1. Why do you want to do this? Is it because you've recently learnt that OOP is great, and you want to use it everywhere, or do you have a specific reason for writing OO jQuery? Remember: Just because a technology (such as jQuery) or methodology (such as OOP) is great sometimes, or even most of the times, it's not great all the time.

  2. How (and why) would you write OO javascript? Don't forget that jQuery is just a library extending the javascript language, nothing else. Many times, the same rules and reasoning apply for javascript with jQuery as for javascript without jQuery.

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

4 Comments

+1 Good questions to consider, and even jQuery isn't "object-oriented" in core, at least in way way some things are written. Some functions, etc are created on the fly from arrays of strings, almost all shortcuts are like this...some would debate whether the way it sets up it's object structure is, well, object-oriented at all.
Interesting article on jQuery being a monad (a concept in functional programming): importantshock.wordpress.com/2009/01/18/jquery-is-a-monad
Thanks for your reply. I have seen the jquery code in some site in oblect oriented method like these var test={ var m:function(){ }, var p:function(){ } }; what is the advantage in jquery to write all my static code in this way
@anoopkattodi: I have never actually seen that exact approach, but I can't say I see any direct advantages in writing OO jQuery, except if you have some requirement that everything should be OO (in which case you have a good reason to question that requirement...). In this case, I think you're heading down the wrong track: jQuery was not (primarily) designed to be used in OOP, and you will still need some kind of non-OO "hook-up" that enables you to instantiate the first objects, or invoke the first method call. Conclusion: don't make things harder than they are, just because you can.
1

As others have mentioned, a little more information on what you are trying to accomplish would help us provide more specific information, but the javascript module pattern might be of interest to you as you learn.

Comments

0

Not sure what you're asking, jQuery is inherintly object oriented to some degree, using Json and other structures help? Is it possible to give examples that are letting you down with regards OO.

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.