I\'m a bit confused, how can I create public and private members.
My code template so far is like:
(function()){
var _blah = 1;
someFunction =
In javascript every object member is public. Most popular way of declaring the private field is to use the underscore sign in it's name, just to make other people aware that this is private field:
a = {}
a._privateStuff = "foo"
The other way to hide the variable is using the scopes in javascript:
function MyFoo {
var privateVar = 123;
this.getPrivateVar = function() {
return privateVar;
}
}
var foo = new MyFoo();
foo.privateVar // Not available!
foo.getPrivateVar() // Returns the value
Here's the article that explains this technique in details:
http://javascript.crockford.com/private.html