News for hackers. Stuff that matters.
Re:Sugar is a new Javascript library for working with native... by jashkenas on Wednesday July 20, 2011 @11:18AM (#2785901)
Before diving in -- it's always great to see more takes on utility programming in JS, especially when there's a clear difference of philosophy. That said...

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.

Re:Sugar is a new Javascript library for working with native... by Bowser on Wednesday July 20, 2011 @11:33AM (#2785977)
First of all I'm impressed with you being objective and not gnawing my head off even after discovering probably the thorniest part of the library (and so soon too)! I am aware of and on your side about the issues with patching the Object.prototype.

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.

Re:Sugar is a new Javascript library for working with native... by Bowser on Wednesday July 20, 2011 @01:55PM (#2786703)
Again, thanks for the input! I've changed the site to emphasize that point about Underscore.js (as you suggested), and also added a page explaining more about (not) patching Object.prototype. Still don't want to add docs for "enableSugar"... not sure yet that's the direction I want... may remove it later.
Re:Sugar is a new Javascript library for working with native... by jashkenas on Wednesday July 20, 2011 @02:12PM (#2786777)
Thanks for the edits. Much appreciated.