The way of good scoping in JavaScript

kristijandz

New Member
I am not a really good JavaScript user but I can get things done with it. I am not proud of the code I have written in JavaScript, so I decided to change that. Here is my first step:I am trying create my own library for a project and the below is the initial structure.\[code\]window.fooLib = {};(function (foo) { "use strict"; foo.doSomeStuff = function(param1) { console.log(new AccommProperty(param1)); } //some internal function function AccommProperty(nameValue) { var _self = this; _self.name = nameValue; }}(fooLib));\[/code\]I used immediately invoked function expression here to initialize my variable. In this case it is \[code\]fooLib\[/code\].I am not sure if I should do some other things to make \[code\]window.fooLib\[/code\] more safe. I mean it can be overridden by any other code which will run after my code if I understand JavaScript correctly.What are your thoughts?
 
Top