On Feb 18, 2:53 pm, pbcomm <pbc...@gmail.com> wrote:
> This might be a stupid question, but I have to ask ...
> What is the reason for not having functions like isString, isNumber,
> isBoolean, etc? Is it just because that would create extra function
> calls?
The simple reason for me is that typeof tells you the type, it doesn't
tell you for certain whether the tested variable is callable or not.
Native objects that implement [[call]] must return 'function',
however host objects can return any value they like, so:
if (typeof foo != 'function')
doesn't mean foo isn't callable unless you *know* it is a native
object.
The same goes for all the other is(whatever) functions. The use of
instanceof is not a suitable alternative in a general sense as it
doesn't work across frames.
--
Rob