Good day to everybody,
is there a method to augment the javascript Object and Function elements avoinding conflict issues? Let me be more specific:
Suppose i have 2 .js files :
ex1.js has Object.prototype.aMethod=function(){/*a function*/}
ex2.js has Object.prototype.aMethod=function(){/*another function*/}
In this situation, the ex1.js augmentation is overwritten by the one on ex2.js .
My question :
Is there a way to limit the effects of an augmentation to his file context, or better, to a module context?
EDIT:
Actually, i am reading crockford' s book JavaScript: the good parts, where he uses the prototype augmentation of Object and Function as something normal to do, without talking about the conflict issue. that' s strange, since the book leans to not pollute the global namespace. So i thought there must be some sort of workaround.
Object.prototype.Objectis wrong. You should useaMethod(thisObj, args...)instead ofthisObj.aMethod(args...)at the very least.