I'm converting a JavaScript library to Haxe. It seems Haxe is very similar to JS, but in working I got a problem for function overwriting.
For example, in the following function param
can be an an integer or an array.
JavaScript:
function testFn(param) {
if (param.constructor.name == 'Array') {
console.log('param is Array');
// to do something for Array value
} else if (typeof param === 'number') {
console.log('param is Integer');
// to do something for Integer value
} else {
console.log('unknown type');
}
}
Haxe:
function testFn(param: Dynamic) {
if (Type.typeof(param) == 'Array') { // need the checking here
trace('param is Array');
// to do something for Array value
} else if (Type.typeof(param) == TInt) {
trace('param is Integer');
// to do something for Integer value
} else {
console.log('unknown type');
}
}
Of course Haxe supports Type.typeof()
but there isn't any ValueType
for Array
. How can I solve this problem?