Posted By

pablo_PXL on 01/31/11


Tagged

javascript type ducktyping


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gauravjassal


JavaScript Ducktyping


 / Published in: JavaScript
 

URL: http://www.twitter.com/pablo_PXL

Guess the type of any object applying ducktyping

  1. function type(o){return o.call?"function":o.pop?"array":o instanceof Boolean?"boolean":+o==o?"number":o.charAt?"string":o.toString()=="[object Object]"?"object":"undefined"}

Report this snippet  

You need to login to post a comment.