Jump to content

PIXI element typof


charlie_says
 Share

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?

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...