PIXI element typof

Recommended Posts

I'm trying to write a function that's can have several different elements passed through to it. It could receive a texture, or a sprite, or a container. I'd then be able to handle what happens next...

But, as all those items return typeof Object, I'm a little uncertain as to how best to differentiate.

Is there a way I can test for they type?

Share this post

Link to post
Share on other sites

instanceof works, but in general case, JS doesn't have types, its ambigious,  so its fine use fields to make custom "instanceof". For example, in TS you can make functions like `isSprite(d: DisplayObject )  : d is Sprite { return d.vertexData !== undefined }`. Its very big topic, I cant just explain it in one line, I just say that your question  makes sense.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.