In my object I need to use this.foo like 50 times all over the place. I think it looks really ugly and unprofessional. I’ve tried using a closure but then I can’t figure out how to call functions inside the closure from outside the closure.
function worker(input) {
return {
foo: "Hello World!",
work: function () {
alert(foo); // FAIL
alert(this.foo); // !FAIL but ugly
};
}
}
One or two this.foo is fine but they are all over the place. Is there a way around this.foo?
You can scope the reference to within the function and use a property getter and setter for
foo:Why do you think that
this.foois ‘ugly’?