I have this code:
var obj = function (i) {
this.a = i;
this.init = function () {
var _this = this;
setTimeout(function () {
alert(_this.a + ' :: ' + typeof _this);
}, 0);
};
this.init();
};
obj('1');
obj('2');
obj('3');
new obj('4');
The script alerts '3 :: object' three times and '4 :: object' once.
I know why this is. It because new obj('4') creates a new instance with it's own memory space and the calls prior share their memory space. When in the code of obj how can I determine if I am a new object or a function, since typeof _this just says 'object'?
Thanks.