Is it ok to invoke a returned function that is creating a closure like in my code below?
So that when gaining access to the html I do not have to do a Bay.HTML()(); ?
Bay.prototype.HTML = function () {
var html;
return function () {
if (!html) {
var td = docCreate('td');
td.setAttribute('id', 'bay' + this.number);
td.setAttribute('class', 'bay');
html = td;
}
return html;
}(); <----------HERE
};
I guess you wanted
This assigns the function which is returned from the closure to
Bay.prototype.HTML, instead of executing a useless function instantly every timeBay.prototype.HTMLis invoked – not really creating a closure.