Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype VS jQuery - Strengths and Weaknesses?

I don't want to open another "Yet Another Js VS Js" thread.

I guess, in the end Prototype and jQuery are both JS and have almost the same methods and functions and need almost the same lines of code for identical tasks.

For a real Rich Internet Application, what are the real strengths and what the weaknesses in Prototype vs. jQuery?

like image 900
Luca Filosofi Avatar asked Apr 15 '10 10:04

Luca Filosofi


People also ask

Is jQuery more efficient than JavaScript?

Nearly all plain Javascript functions will be faster than jQuery operations. This is because jQuery has overhead in creating a jQuery object in order to be more flexible, allow for chaining, support collections, etc...

What is jQuery prototype?

All objects have a prototype property. It is simply an object from which other objects can inherit properties. The snippet you have posted simply assigns an object with some properties (such as init ) to the prototype of jQuery , and aliases jQuery.prototype to jQuery.fn because fn is shorter and quicker to type.

Which is better jQuery or JavaScript?

Though JavaScript is the basic language from which jQuery has evolved, jQuery makes event handling, DOM manipulation, Ajax calls much easier than JavaScript. jQuery also allows us to add animated effects on our web page which takes a lot of pain and lines of code with JavaScript.

Should you use prototypes in JavaScript?

There is a clear reason why you should use prototypes when creating classes in JavaScript. They use less memory. When a method is defined using this. methodName a new copy is created every time a new object is instantiated.


1 Answers

I initially liked the idea of Prototype's extending elements with new or modified methods.

However, I've discovered a number of reasons this is a bad thing (TM)

Do some googling and you'll probably find some other reasons, but the primary reason is that Prototype cannot be guaranteed to "play nice" with other frameworks or libraries, as other libraries expect the behaviour of elements and methods to be "standard", and due to the things Prototype does, you may find a number of things that are broken by it.

The most recent example I discovered was Prototype screwing with JSON and stringify. I was using EasyXDM, and it simply did not work in some cases where the prototype.js library was loaded. As I was writing a framework to be used by others, and thus did not have control over the content of the page, I needed to create and do everything in an IFRAME in order to ensure things such as prototype.js did not play havoc with what I was trying to do.

...so jQuery wins hands-down for me, because I just don't think its right for a framework to automatically screw with the standard behaviour of the DOM and javascript. YOU should be in control of these things, Prototype takes some of this control away from you....

like image 144
Graza Avatar answered Nov 07 '22 04:11

Graza