dmcblue
dmcblue

Reputation: 363

Haxe: How to check if a variable is a function

I would like to see if a Dynamic variable in Haxe is a Function.

Using Std.is(v, Function) does not work as Function is not a recognized key word for types.

I tried fooling around with $type(v) but it doesn't seem to actually return a string. Sys.println($type(v)); does output <function> but it doesn't seem like I can work with it.

I also tried to use Std.is with typedef but no luck as typedefs are not variables.

TDLR: I want a function that takes a variable and outputs a boolean based on if it is a function.

Upvotes: 4

Views: 360

Answers (1)

Gama11
Gama11

Reputation: 34148

You're looking for Reflect.isFunction().

Upvotes: 4

Related Questions