I’m trying to imitate some sort of constructor like in other programming languages.
If I do it like this it doesn’t work. :/ Sorry for being dumb! :/
Thanks for the help!!
function foo(){
this.makeVar = function(){this.newVar = 'hello world'}();
}
var test = new foo();
alert(test.newVar);
Because you are calling the (anonymous) function directly, and not as a method on an object. So
thisiswindow.Copy the value of
thisin the outside function to a variable that is still available on the inside function.