473,563 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prototype.js criticism

Hi,

I've been reading the recent posts and older archives of
comp.lang.javas cript and am surprised by the sentiments expressed about
the prototype.js library for a few reasons:

1) The library has been referred to as "junk" many times which is a
strong opinion against the relatively high popularity of the library. I
know popularity doesn't make something good.

2) People who use it are advised to "get a minimal clue". (Paraphrased.
Search archives "prototype. js minimal".)

3) Those who criticize so strongly must believe they know better but
the posts I saw containing the criticism did not indicate why the
library is so bad.

I have used the prototype.js library a bit with a mixed experience.

I had very little success with the Enumerable iterators. Constant
problems. They make for code that is bulky enough to match the size of
a JavaScript for loop. In Ruby these types of methods are great but I
don't think they work so well in JavaScript the way prototype.js
implements them.

I have enjoyed using the event parts of prototype.js without any
problems or even reading any of the code. It's usually the goal of a
library to make it so the user doesn't have to know the library's
internals. I'll count this as a success for prototype.js. However,
after reading such criticisms I decided to look at the code just in
case I got lucky so far. It turns out that for my application I was
able to take only about 90 lines of prototype.js's 1800 lines. These
lines are below. I've read them now. They seem ok to me. I would like
to know if anyone thinks this is a weak part of the prototype.js
library and why? Particularly comments regarding the browser
incompatibility workarounds as well as overcoming the IE problems of
the "this" keyword and bubbling (discussed on
http://www.quirksmode.org/js/events_advanced.html).

One thing I wish was that prototype.js used a namespace (discussed
http://blog.dreamprojections.com/arc...2/27/450.aspx). This
would mean the code that uses the library would not look quite so cool
since it would not be possible to extend Event, Function, String, etc.

What do you like or dislike about prototype.js? Any reasons why
prototype.js is "junk"?

I think a critical discussion of this library would be very educational
for many people. I know that I am trying to "get a minimal clue".

Thanks,
Peter
// ------------------------------------------------------------

Function.protot ype.bindAsEvent Listener = function(object ) {
var __method = this;
return function(event) {
return __method.call(o bject, event || window.event);
}
};

function $() {
var elements = new Array();

for (var i = 0; i < arguments.lengt h; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getEle mentById(elemen t);

if (arguments.leng th == 1)
return element;

elements.push(e lement);
}

return elements;
};

// -------------------------------------------------------------------

Event.element = function(event) {
return event.target || event.srcElemen t;
};

Event.stop = function(event) {
if (event.preventD efault) {
event.preventDe fault();
event.stopPropa gation();
} else {
event.returnVal ue = false;
event.cancelBub ble = true;
}
};

Event.observers = false;

Event._observeA ndCache = function(elemen t, name, observer, useCapture)
{
if (!this.observer s) this.observers = new Array();
if (element.addEve ntListener) {
this.observers. push([element, name, observer, useCapture]);
element.addEven tListener(name, observer, useCapture);
} else if (element.attach Event) {
this.observers. push([element, name, observer, useCapture]);
element.attachE vent('on' + name, observer);
}
};

Event.unloadCac he = function() {
if (!Event.observe rs) return;
for (var i = 0; i < Event.observers .length; i++) {
Event.stopObser ving.apply(this , Event.observers[i]);
Event.observers[i][0] = null;
}
Event.observers = false;
};

Event.observe = function(elemen t, name, observer, useCapture) {
var element = $(element);
useCapture = useCapture || false;

if (name == 'keypress' &&
(navigator.appV ersion.match(/Konqueror|Safar i|KHTML/)
|| element.attachE vent))
name = 'keydown';

this._observeAn dCache(element, name, observer, useCapture);
};

Event.stopObser ving = function(elemen t, name, observer, useCapture) {
var element = $(element);
useCapture = useCapture || false;

if (name == 'keypress' &&
(navigator.appV ersion.match(/Konqueror|Safar i|KHTML/)
|| element.detachE vent))
name = 'keydown';

if (element.remove EventListener) {
element.removeE ventListener(na me, observer, useCapture);
} else if (element.detach Event) {
element.detachE vent('on' + name, observer);
}
};

/* prevent memory leaks in IE */
Event.observe(w indow, 'unload', Event.unloadCac he, false);

Mar 20 '06 #1
12 2186
pe**********@gm ail.com said the following on 3/20/2006 2:26 AM:
Hi,

I've been reading the recent posts and older archives of
comp.lang.javas cript and am surprised by the sentiments expressed about
the prototype.js library for a few reasons:

1) The library has been referred to as "junk" many times which is a
strong opinion against the relatively high popularity of the library. I
know popularity doesn't make something good.
eval is popular also :) But, as you said, popularity doesn't make
something good.
2) People who use it are advised to "get a minimal clue". (Paraphrased.
Search archives "prototype. js minimal".)
The only person I recall using that phrase is Thomas and I won't comment
on that part of it.
3) Those who criticize so strongly must believe they know better but
the posts I saw containing the criticism did not indicate why the
library is so bad.


First, I am not a big fan of libraries to start with. They have there
place but I don't care for them. But the major problem, to me, with
prototype.js is two-fold:

Lack of feature detection - it assumes a lot about what the UA does or
doesn't support without testing for it.

Lack of technical support - That one is obvious from the amount of posts
seen here asking questions about it. You don't see a lot of questions
about Matt Kruse's libraries here (especially compared to prototype.js)
because Matt supports his libraries.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 20 '06 #2
pe**********@gm ail.com wrote:
It turns out that for my application I was
able to take only about 90 lines of prototype.js's 1800 lines.


And that right there is one of the big criticisms of prototype.js.

It is a big monolithic do-everything solve-every-problem approach to
scripting, and in most cases it's over-kill.

In an environment like this group where many 'experts' are of the opinion
that libraries are bad and that everyone should become a javascript expert,
you can imagine why such a big library approach is looked down upon.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 20 '06 #3
pe**********@gm ail.com wrote:
What do you like or dislike about prototype.js? Any reasons why
prototype.js is "junk"?

I think a critical discussion of this library would be very educational
for many people. I know that I am trying to "get a minimal clue".


Search the archives.
HTH

PointedEars
Mar 20 '06 #4
Matt Kruse wrote:
pe**********@gm ail.com wrote:
It turns out that for my application I was
able to take only about 90 lines of prototype.js's 1800 lines.
And that right there is one of the big criticisms of prototype.js.

It is a big monolithic do-everything solve-every-problem approach to
scripting, and in most cases it's over-kill.


That is one point.
In an environment like this group where many 'experts' are of the opinion
that libraries are bad and that everyone should become a javascript
expert, you can imagine why such a big library approach is looked down
upon.


That is not a point at all for me. On closer observation, you will
recognize that I use and provide many script libraries myself. I will
probably use and provide a script library for XMLHTTP requests in the
near future.
PointedEars
Mar 20 '06 #5
pe**********@gm ail.com writes:
I've been reading the recent posts and older archives of
comp.lang.javas cript and am surprised by the sentiments expressed about
the prototype.js library for a few reasons:

1) The library has been referred to as "junk" many times which is a
strong opinion against the relatively high popularity of the library. I
know popularity doesn't make something good.
Some people seem to need to vent their opinions in public. Without
further arguments, it's just noise, since it doesn't help you evaluate
whether the expressed opinion is one you can agree with, or just
unfounded rambling.
2) People who use it are advised to "get a minimal clue". (Paraphrased.
Search archives "prototype. js minimal".)
See 1.
3) Those who criticize so strongly must believe they know better but
the posts I saw containing the criticism did not indicate why the
library is so bad.
See 1.
I have used the prototype.js library a bit with a mixed experience. .... What do you like or dislike about prototype.js? Any reasons why
prototype.js is "junk"?


I haven't even used it, so I am not in a position to unqualified call
it junk. I have my reasons for not using it, which might be misguided
ones, but I have yet to see something contradict them :)

- The most accessible features of the prototype library are shortcut
functions. I can see why people want to abstract away feature detection
and calls like document.getEle mentById if you use them much, but being
a Java programmer by day, I value readability quite highly. Functions
like $H, $A, and even $ are cute, but only readable by the initiated.
Some of the shortcuts seem to be there just because they can. Compare
Form.getElement s("myform")
to
document.forms["myform"].elements
Saving seven characters is not excuse enough for changing a known idiom
to a proprietary shorthand.

- Size! I too am against monolithic libraries. If the different features
could be extracted and used independently, you could compile your own
library with just what your site needs. From what little I have seen,
the features of prototype.js are depending on each other so much that
separating them is non-trivial, i.e., not something a simple user can
do.
The size of version 1.4.0 is 47445 bytes. That takes 10+ seconds on
a 28.8K modem, which is far too much.

- The class creation features have confused me before. A lot of action
seems to be happening in a slightly non-standard way, where again only
someone familiar with the framework has any chance of reading the
result. That said, I think the library has simplified somewhat since
then (or people have stopped trying to do everything in a roundabout
way), and the examples I see now are much more readable.

- It extends Array.prototype . That means that you can't do
for (var i in myArray) { ... }
to iterate over the assigned elements of a sparse array without
getting unexpected indices like "each" and "all". This is simply
bad citizenship, since it can break other Javascript functions
unrelated to prototype. This would be a deal breaker for me.
I'm not alone, shows Google:
<URL:http://blog.metawrap.c om/blog/WhyIDontUseTheP rototypejsJavaS criptLibrary.as px>
It appears version 1.4 doesn't extend Object.prototyp e any more,
which is good, but Array.prototype is still heavily modified.
All in all, it seems to me that prototype.js is maturing and does have
some useful additions, but it tries to be a framework, not a library,
and that hinders readability and maintainability for people not familiar
with it.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Mar 20 '06 #6
Thomas 'PointedEars' Lahn wrote:
I will
probably use and provide a script library for XMLHTTP requests in the
near future.


Why? One of the 10,000 out there already didn't quite do what you want? :)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 20 '06 #7
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
I will probably use and provide a script library for XMLHTTP requests in
the near future.


Why? One of the 10,000 out there already didn't quite do what you want? :)


Probably not. I have yet to review Sarissa, though.
PointedEars
Mar 20 '06 #8
Thomas 'PointedEars' Lahn wrote:
Why? One of the 10,000 out there already didn't quite do what you
want? :)

Probably not. I have yet to review Sarissa, though.


What is it that you want, exactly?
My lib does purely js-side stuff. I'd be curious to know what it doesn't do
that you'd be looking for.

I also find that much of the preference for ajax libs comes from personal
style. What seems logical to one person seems awkward to another. When I
wrote mine, I first wrote code to implement a page with ajax functionality.
I wrote the calls how I wanted to use it, then wrote the lib that acted on
the methods. So the interface to the functionality felt right to me. Others
have said the same. But of course, not everyone thinks the same way!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 20 '06 #9
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Why? One of the 10,000 out there already didn't quite do what you
want? :)

Probably not. I have yet to review Sarissa, though.


What is it that you want, exactly?
My lib does purely js-side stuff. I'd be curious to know what it doesn't
do that you'd be looking for.


I have not reviewed your library either, since I have no need for XMLHTTP
requests for the time being. If I discover something in the process that
is not possible when using your library, rest assured you will be the first
one to know.
PointedEars
Mar 20 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

62
3859
by: Xah Lee | last post by:
Criticism versus Constructive Criticism Xah Lee, 2003-01 A lot intelligent people are rather confused about criticism, especially in our “free-speech” free-for-all internet age. When they say “constructive criticisms are welcome” they mostly mean “bitching and complaints not welcome”. Rarely do people actually mean that...
28
2616
by: Diodeus | last post by:
I would like to set up an event observer outside of an object, so I can't use this.bindAsEventListener. How can I pass the correct object reference? I tried something like this, and various other variations, but no luck. This works when I set it up from inside the object, using "this.", ...
31
3096
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked around here? If so, do you know if Ajax.NET can be used without prototype.js? -- "The most convoluted explanation that fits all of the made-up...
17
3132
by: Steve-O | last post by:
The following code works great in FireFox, Opera, Netscape, Safari, and Gecko, but NOT IE. Why? I tried using 'native' js with setInterval and setTimeout, but I get the same result. My IE security settings are not an issue. Anyone have any insight on this? Thanks! -sh
8
1941
by: Chad Burggraf | last post by:
Hi all, I'm brand new to this newsgroup. I've been reading the FAQ's and some other documentation submitted by regulars of the group (such as "Javascript Best Practices" at http://www.javascripttoolbox.com/bestpractices/#prototype) and am discovering that there is general distaste for prototype.js. In my first post to this group I...
23
1750
by: Dautkhanov | last post by:
Hello ! Does anybody have cutted version of prototype.js with the AJAX functionality only? I am a new in prototype.js topic, so I think this task should be done by other developers. Maybe protorype.js should be splitted into small pieces of the js scripts with groupped functionality
11
1763
by: webgour | last post by:
Hello, I am wondering why the following works, on IE6, but with an error : "Not implemented". function TEST(){} TEST.prototype.Initialize = function() { var mImage = new Image(); var mDate = new Date();
56
2949
by: ashore | last post by:
Guys, I see a fair bit of negativity around re subject package. Can someone share your views, either way? Thanks, AS
83
4128
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about it too? Once I saw a website comparing Prototype to Java and jQuery to Ruby... but now that I read more and more about Prototype, it is said...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.