On 7/20/06, Thomas Fuchs <[EMAIL PROTECTED]> wrote:
The sole point of Prototype is to give the programmer a powerful, opinionated toolset, to make programming JavaScript less pain (with some extra special sugar-on-the-top for Ruby devs).
How special is this sugar? Below are four randomly selected uses of Prototype.js enumberable methods from Scriptaculous. Yes three of the Prototype.js versions are somewhat shorter but they require the user to download the enumerable part of Prototype.js which is big, tokenize it and compile it. In each of these examples below I gave the native JavaScript versions using an Array or using a "Hash" (JavaScript object as an associative array). Count the number of function calls in each of the Prototype.js versions. One for the enumerable method and then one for each of the conditions. In the compound example the number of function calls is doubled + two. This makes the Prototype.js versions much slower. As I wrote before, the Prototype.js versions require a new maintainer to learn Prototype.js. Also the actual Prototype.js library code is an extra layer of code that can contain bugs. I don't see that the sugar is so sweet. I am not criticising anyone that uses Prototype.js. I am looking at Prototype.js critically. Peter = each == Prototype.js s.droppables.each(function(d){Droppables.remove(d)}); == Native JavaScript with Array var ds=s.droppables;for(var i=0;i<ds.length;i++){Droppables.remove(ds[i])} == Native JavaScript with "Hash" var ds=s.droppables;for(var p in ds){Droppables.remove(ds[p])} = detect == Prototype.js return drop._containers.detect(function(c){return containmentNode==c}); == Native JavaScript with Array for(var i=0;i<drop._containers.length;i++){var c=drop._containers[i];if(containmentNode==c){return c;}} == Native JavaScript with "Hash" for(var p in drop._containers){var c=drop._containers[p];if(containmentNode==c){return c;}} = reject == Prototype.js this.observers=this.observers.reject(function(o){return o.element==element}); == Native JavaScript with Array var os=this.observers;for(var i=0;i<os.length;i++){if(os[i].element==element){delete os[i]}} == Native JavaScript with "Hash" var os=this.observers;for(var p in os){if(os[p].element==element){delete os[p]}} = compound: findAll & each == Prototype.js this.effects.findAll(function(e){return e.state=='idle'}).each(function(e){ e.startOn += effect.finishOn; e.finishOn += effect.finishOn; }); == Native JavaScript with Array for(var i=0;i<this.effects.length;i++){var e=this.effects[i];if(e.state=='idle'){ e.startOn += effect.finishOn; e.finishOn += effect.finishOn; }} == Native JavaScript with "Hash" for(var p in this.effects){var e=this.effects[p];if(e.state=='idle'){ e.startOn += effect.finishOn; e.finishOn += effect.finishOn; }} _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs