473,698 Members | 1,901 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
12 2194
pe**********@gm ail.com said on 20/03/2006 5:26 PM AEST:
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.
Yup.

2) People who use it are advised to "get a minimal clue". (Paraphrased.
Search archives "prototype. js minimal".)
That is one opinion, only got 2 hits when searched. Even 'prototype.js
junk' only got 3 unique hits.

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.


A thorough evaluation of 1700 lines of code with 230 (or so) functions
would take quite some time. The main issues are the size of the
library, difficulty of abstracting parts of it to reduce bloat, changes
to in-built objects and obfuscation - what does $('blah') mean to the
uninitiated?

Some methods/function appear to offer very little, e.g. $() doesn't do
any feature detection or offer any fall back for older browsers. If I
really want a bunch of element references in an array I can write my own
function with very little effort.

The other big problem is that the author publishes it without any
documentation or comments. No doubt the response is 'the code is the
best documentation' but to me that is laziness or lack of confidence -
the author doesn't want to say what it should do or why it does it for
fear of being wrong or highlighting an error.

Or maybe some Picasso-esque fear of being understood too clearly and
therefore trivialised. Who knows?

The result is that it is very hard to determine whether it is 'working'
correctly or not, it just does what it does. The various attempts I've
seen at documenting it (discovered via Google) don't help at all.
--
Rob
Mar 21 '06 #11
RobG wrote:
pe**********@gm ail.com said on 20/03/2006 5:26 PM AEST:
[Why is Prototype.js considered junk?]

[...]
The main issues are [...] obfuscation - what does $('blah') mean to the
uninitiated?

Some methods/function appear to offer very little, e.g. $() doesn't do
any feature detection or offer any fall back for older browsers. [...]


The `$' identifier being used for not machine-generated code is also
disregarding ECMAScript Ed. 3 identifier recommendations , as Richard
pointed out shortly ago.
PointedEars
Mar 21 '06 #12
Hi All,

Thanks for the insiteful replies. The ideas mentioned here will
definitely help me build a better JavaScript library framework for my
project with small modular chunks that can be read by any JavaScript
programmer. I think I have something very cool cooking for libraries in
general and a user interface widgets library in specific.

Peter

Mar 21 '06 #13

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

Similar topics

62
3896
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 “criticism without suggestion of possible solutions are not welcome” or “impolite criticism not...
28
2631
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.", Event.observe(targetId,'click',targetId.select.bindAsEventListener(this),false);
31
3136
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 facts is the most likely to be believed by conspiracy theorists. Fitting the
17
3151
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
1946
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 recommended a fix that happened to use some functions from the prototype.js library. I may now be...
23
1759
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
1773
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
2995
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
4198
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 that Prototype actually came from Ruby on Rails development and the creator of Prototype created it...
0
8672
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 usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9021
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4361
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
2
2323
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.