function obj(){
var self = this;
var privateField = "I'm privateField value";
var privateMethod = function(){
alert('Whoo!');
}
self.publicField = "I'm publicField value";
self.publicMethod = function(){
return privateField;
}
self.publicMethod2 = function(){
setTimeout(
function(){
privateMethod.call(self);
},
1000
);
}
}
var obj = new obj();
console.log(obj.privateField); //Undefined
console.log(obj.privateMethod()); //TypeError
console.log(obj.publicField);
console.log(obj.publicMethod());
obj.publicMethod2();