Sugar is a new Javascript library for working with native JS objects.
sugarjs.com
sugarjs.com
Underscore might be oriented towards performance, but really the main thing -- which it would be great for you to add to the paragraph -- is that Underscore is oriented towards not patching native objects.
To quote from lib/sugar.js, inside of the Object.enableSugar() function:
typeMethods.each(function(m){
Object.prototype['is'+m] = function(){
return instance(this, m);
};
});
hashMethods.each(function(m){
Object.prototype[m] = Hash.prototype[m];
});
Extending Object might be perfectly fine on a webpage that you control, and that you're 100% sure not to include any third-party JS libraries on. But it also means that I'll never be able to use sugar.js in a library that I expect others to use, or in a bookmarklet, or on a large website where third-party code will be included.Cheers, and nicely done with the great documentation site.
So, to be perfectly clear, the Object prototype will NEVER be modified in any way by default! The "enableSugar" method you have found (so resourcefully, I might add :) ) is something I added in later as an "opt-in" way of using objects as hashes in pages where you ALREADY have assurance that it won't break. It is intended as something of the reverse of "noConflict" in jQuery. By using this method you're basically saying that you're ready to live on the edge and will take responsibility for what breaks. More importantly you can turn it off again if something does start to break.
Now that having been said, even though I've added this method there is ZERO reference in it to the documentation. A few reasons for this: one is the backlash I knew I would get for even MENTIONING the sacred Object prototype (you may have proved that point, heh)... the other is that I'm not sure I ever really want it used... in the first place I sort of intended it as more of an "easter-egg" and I'm not sure I ever want to mention it in the docs...
In any case though it will NEVER be a default, and for precisely the reasons you've mentioned.
There are many libraries that enhance aspects of writing js apps that dont sacrifice performance.
Additionally, and I may be wrong here, but in my experience any lib that modifies native objects tends to be a bad idea.
Now of course there are other considerations like collisions with Prototype itself or other libraries. But in the end, any library that modifies these native types is generally speaking meant to exist on it's own, without having to co-exist with other libraries of similar type. Now I realize that can't ever be 100% guaranteed, but if that limits the environments where Sugar can be included, then so be it. Now that having been said I am still going to great lengths whenever possible to minimize these collisions and in more than a few places have actually re-aligned Sugar syntax to match Prototype, so long as it doesn't violate my first rule of having intuitive syntax that "reads". Additionally it's worth restating that Sugar never overwrites methods that are already defined, and so any page that includes Prototype will always get Prototype methods in the case of a collision. I'm currently looking into an elegant way of having devs manually override Prototype methods/classes if they so desire. I also believe that the danger of modifying native objects can be greatly mitigated by extensive unit testing, and this was the main reason I've taken the unit tests as far as I have (to be honest I've gone a bit nuts with them). To summarize, there is a certain extent to which I disagree with the statement that "modifying native objects is bad" and a certain extent to which I agree. To the extent that I agree I think that making good design decisions, mitigating collisions, and having proper unit tests to tie it all together can more than make up for anything that might be considered "bad".
Lastly I want to mention that I just released v0.9.1, which uses Object.defineProperty to map these methods to the prototype. It's a long story (check out MozDev for more info) but the result is that in modern browsers including IE9, modifying the prototype object no longer breaks the for..in loop. I actually had to put a new "warning" into the unit tests that include Prototype because I wanted to put in a unit test assuring this, but Prototype breaks it!
EDIT: I had quoted a line number figure, but it's mostly comments (except for those few pages of Japanese characters ;)
But otherwise, good work. Library looks useful, and a great and very descriptive website!