If you want to prevent your variables from being overwritten, you can use Object.defineProperty() with write options: false, configurable: false. In your case:
(function () { "use strict"; var foo = {}; //some internal function function AccommProperty(nameValue) { var _self = this; _self.name = nameValue; } foo.doSomeStuff = function(param1) { console.log(new AccommProperty(param1)); } Object.defineProperty(window, "foolib", {value:foo}); }());
However, there is no good reason for this. EcumScript 5.1 is required for operation, and there are no gaskets around it; maybe something with getters / setters to prevent overwriting with the = operator.
But it should also not be necessary to make your library unregistered. Just don't use the code on your site that overrides lib. Or maybe someone even wants to rewrite your functions with a different, better lib with the same interface?
If the question is about a library to be shared, with possible namespace conflicts with others, you can take a look at jQuery.noConflict .
Bergi
source share