Undefined into Boolean
Method to get a one-time execution using an object property that starts out undefined, then is assigned True and False
by David McClelland
HTML
<input type=button value="try" onclick="testFalseOrUndefined()" />
JavaScript
thisWidget= {};
testFalseOrUndefined = function() {
alert("trying");
if (!thisWidget.selectionUpdating) {
alert("thisWidget.selectionUpdating: " + typeof thisWidget.selectionUpdating);
if(thisWidget.selectionUpdating !== undefined){
alert("thisWidget.selectionUpdating: " + thisWidget.selectionUpdating);
}
thisWidget.selectionUpdating = true;
alert("thisWidget.selectionUpdating: " + thisWidget.selectionUpdating);
setTimeout(function() {
thisWidget.selectionUpdating = false;
alert("thisWidget.selectionUpdating: " + thisWidget.selectionUpdating);
}, 100);
}
};