I want to extend Object.prototype to basically support notifications in JSON data and html elements through the user interface infrastructure.
Object.prototype.setValue = function(key,value){ // this simply sets value as this[key] = value // and raises an event Binder.setValue(this,key,value); }; Object.prototype.getValue = function(key){ return Binder.getValue(this,key); };
However, based on this question, the Object.prototype JavaScript Extension and several others, people say that we should avoid the Object.prototype extension, instead, any other type is fine.
If I do not, then my code will become larger, for example
window.myModel.setValue("currentStatus","empty");
should be written like
Binder.setValue(window.myModel,"currentStatus","empty");
I want to know what will go wrong if I use these methods? will this cause jQuery to behave unexpectedly? I saw once that jQuery ajax request also calls prototype methods (as they refer to event processing functions).
What are the other side effects of this? I know this fails (var x in obj), but basically we can use obj.hasOwnProperty, which should help correctly?
javascript object prototype-programming
Akash Kava Dec 01 '11 at 12:08 2011-12-01 12:08
source share