Your bar
is not the same references as what i_bar
is referencing. Value types are not by reference, so you are copying bar
into the return object, but it is not the bar
that your function is referring to. Try this:
var obj = function()
{
var self = this;
function i_bar(){return ++self.bar;}
self.bar = 10;
self.i_bar = i_bar;
return self;
}();