I’ve been looking through some library javascript source code and I’ve found a statement that I totally don’t understand. This library is based on dojo and uses its implementation of “class inheritance”. Here is a simplified version of code that is a subject:
dojo.declare("myCustomClass", {
constructor:function(){
// what does this statement mean?
isContentShowing : false;
//here some code that uses isContentShowing in callbacks
dojo.connect(this, "fakeEvent", this, function(){
if(this.isContentShowing){
//do some stuff
}
//do more stuff
});
}
});
So the question is what does the isContentShowing: false; inside function body mean?
It’s not a variable. It is a label:
In this case, it is useless: it is not used as a label, it does not perform an assignment, and the result of evaluating
falseis discarded.I suspect a
=andthisare desired asthis.isContentShowing = falsemakes more sense given the conditional below. Perhaps the original author never ran into/realized this bug due tothis.isContentShowingevaluating toundefined(and thus still being falsey, like, well,false) later on.Or, as Chris suggests in a comment, the intent might have been: