A pedant would reply that it’s all JavaScript under the hood – an ECMA-ratified universal standard language. But Prototype (hence the name*) modifies that language to suit its own ends, and any other library or even hand-coded JavaScript can run afoul of these modifications. Prototype adds major functionality to the language in return – it’s not breaking things for fun. But it can only drag the language so far (kicking and screaming): once Prototype is in the environment, you cannot rely on the mistaken assumption that there are actual Array primitives in JavaScript. Under the hood, an Array is a numerically-indexed Object, and so if you use for(i in my_array){ ... }
to loop over one, you will get all the extra properties that Prototype has added to the Array object in addition to the values you expect.
As for preference of Prototype over jQuery, I often say that I could build jQuery with Prototype, but not the other way around. Prototype is a foundational toolkit, better-suited for building tools than implementing canned solutions. It appeals to the tinkerer and craftsman in me. It also warps JavaScript to be more like Ruby, and that’s a Very Good Thing, IMO.
Walter
*JavaScript has a unique inheritance model, called Prototypical Inheritance. When you alter the prototype of any object (like Array), all copies of that prototype are also changed, immediately. It’s like quantum entanglement, with all the “spooky” that goes with that idea.
For one example, Prototype extends the Array object to support the idea of enumeration (something that was just added in EcmaScript 6 – remember, Prototype is nearly ten years old, and ran initially on EcmaScript 3 or 2). The ideas pioneered in this library are slowly being added to the base language. Think about that for a moment.
But because JavaScript uses prototypes, Prototype does this extension by altering the prototype of all Array objects everywhere. Whenever you add methods to a base object, those methods are not marked as being private (they can’t be, for security reasons) and so they appear to be additional members of an array if you loop over its members in the naive for foo in bar
manner. If you do a “proper” for loop, then you get the correct behavior, and there’s a whole page in the documentation to explain this. But if you use Prototype’s each()
method, you get an even more powerful set of behaviors.
On Jun 18, 2014, at 5:17 AM, Thomas Kimmich wrote:
We have a common Mark-Up language, a common Styling language but we haven’t got a common library for dynamic stuff. Scripty experts can’t deal (or don’t want to) with jQ and vice versa. Even writing functions is entirely different.
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options