I'm a fairly experienced programmer in the .NET and Java realms, and I've started reading up on JavaScript. I bought Douglas Crockford's "The Good Parts" book, and I'm immediately put off by a few things.
One is modifying the fundamental types without need:
if (typeof Object.create !== 'function') {
Object.create = function (o) { //Really... 'o'? For a parameter you're only using twice?
function F() {}
F.prototype = o;
return new F();
};
}
newObject = Object.create(oldObject);
Obviously creating a function with this purpose is useful and saves time, but WHY ON EARTH is he recommending creating it on Object? Three breaths ago he espoused that globals are evil, and then he proceeded to monkey patch Object. He even tests if it already exists, and just assumes that if some other library did it for him the implementation is the same.
Is there some reason not to create this in the JS equivalent of a namespace? ie
MY_UNIQUE_UTIL_LIBRARY.create = function(obj){...}; //The name would be shorter in reality.
Don't get me wrong, I think monkey patching is useful, but it's something you do when there's an inherent benefit. I don't see one here? Is there one?