Resolve "Javascript 'instanceof' support"
Closes #105 (closed)
I decided to make jsInstanceOf
return a JSVal
, which is the least surprising because instanceof
is an expression, not a statement. I have added .??
which is like .?
combined with a conversion with a default value, so you can say:
... appJSWorld f ...
where
f w
# (m,w) = jsNew "Map" () w
# (b,w) = m jsInstanceOf "Object" .?? (False, w)
= jsTrace (if b "Map is an Object" "Map is not an Object") w
@baslijns @eveen @smichels: .??
and .$?
now allow you to perform a conversion with a default value (previously e.g. jsValToInt` 0 jsVal
) together with .?
/ .$
. This allows shorter and more readable code in many cases, for example:
Old:
# (x,w) = expr .? w
x = jsValToString` "" x
# (y,w) = (f .$ (a,b,c)) w
y = jsValToInt` 0 y
New:
# (x,w) = expr .?? ("", w)
# (y,w) = (f .$? (a,b,c)) (0, w)
The functions remain available apart from .?
/ .$
as well, but now as the class member fromJS
. There are no changes to the functions without backtick (e.g. jsValToInt
), which return a Maybe.
I will go through iTasks and VIIA to replace cases of jsValTo{Int,Bool,String,Real}`
with .??
, .$?
, or fromJS
. After this, at some point in the future, the jsValTo{Int,Bool,String,Real}`
series will be removed. The non-backticked functions will remain, because they may be needed to solve overloading.
So, for new code, please use .??
, .$?
, or fromJS
, but avoid jsValTo{Int,Bool,String,Real}`
.