3 ms·
Honestly, I find it to be more the common superstition rather than the common wisdom. That is not to say there's no truth to it, but I find that I hear ppl repe
by Bowser 15y ago
Honestly, I find it to be more the common superstition rather than the common wisdom. That is not to say there's no truth to it, but I find that I hear ppl repeating it religiously without really knowing why. The main danger comes from extending Object.prototype, which Sugar will never do. In response to a lot of people with the same concerns as you, I've put up a page explaining this in more detail (http://sugarjs.com/native http://sugarjs.com/native). I think the idea of extending other objects may have gotten a bad rap due to this, but the fact is there is a marked difference, and frameworks like Prototype have known this and found their niche here for many years.
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!