Object.prototype.objSayHello = function(to){alert('Hello, ' + to)};
The above statement means that you attached the objSayHello
function to all the instances that will be created as every instance is child of Object
so the attached event bind to all. For instance,
var newObject = {};
var anotherNewObject = new Object();
function person(name) {
this.name = name;
}
var newPerson = new Person("Ramiz");
newObject.objSayHello("newObject");
anotherNewObject.objSayHello("anotherNewObject");
newPerson.objSayHello(this.name);
While, the other statement is incorrect and will be ignored completely as you're about to discard the prototype
of an object which is parent of all. If the prototype
of Object
can be override then all native instances functionality will be gone. To avoid such a mistake I think this is ignore to be override.