A Better is_a Function for JS
In 2007 I have posted about get_class and is_a functions in JavaScript in order to simulate original PHP functions. Well ... that was crap, since a much simpler and meaningful version of the is_a function can be easily summarized like this: var is_a = function () { function verify(what) { // implicit objet representation // the way to test primitives too return this instanceof what; } return function is_a(who, what) { // only undefined and null // return always false return who == null ? false : verify.call(who, what) ; }; }(); ... or even smaller with explicit cast ... function is_a(who, what) { // only undefined and null // return always false return who == null ? false : Object(who) instanceof what ; } An " even smaller " alternative via @kentaromiura function is_a(who, what) { return who != null && Object(who) instanceof what; } Here a usage example: alert([ is_a(false, Boolean), // true is_...