Boolean properties, &&, and falsy values
-
So I have code that looks like this
property boolean isSomething: otherProp && someUndefinedProp // this happends to be undefined
I looked this up and apparently this is a result of javascript's "&&" operator. It assumes the type of the falsy value. So because undefined is the falsy value, you get undefined back. This produces the following error when ran "Unable to assign [undefined] to bool". My question is basically, should this happen? I feel like the qml type system should be able to convert this to boolean if the value itself is falsy. I could see an argument against this because it is no longer type safe, but at the same time its javascript so I don't know. Granted, I could just make the property var. However, that only gets me so far, if a qml component wants bool I still have to make sure its not equal to false. Anyway, I was just wondering peoples thoughts
-
I think this is just the kind of oddities one has to live with when one lies in bed with a weird language like Javascript. ^_^