Luis,
Let me clarify. Object.extend defines a
static method of the Object class, which means that you can call it without having an instance Object. Object.prototype.extend defines an
instance method, meaning that you must have an instance of Object to use it. Anytime you define something using prototype, you are saying "when an object of this type is created, make sure it has this."
Just calling extend() without either Object or test should cause an error (it did when I tried it). Object.extend() is a direct reference to the function describe as Object.extend (the static method). test.extend() is a direct reference to Object.prototype.extend (the instance method). You can prove this by running the following code:
Code:
Object.extend = function(){
alert("f1");
}
Object.prototype.extend = function(){
alert("f2");
}
var test = new Object();
test.extend(); /* f2 */
Object.extend(); /* f1 */
alert(test.extend == Object.prototype.extend); /* true */
alert(test.extend == Object.extend); /* false */
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/