is there a way to know if a variable passed into a function is a native object? I mean, i have a function that requires only native objects as arguments, for every other type of variable it throws an error. So:
func(Array); //works
func(String); //works
func(Date); //works
func(Object); //works
...
func([]); //Throwr error
func({}); //Throws error
I want to know if there’s a way to distinguish between native objects and everything else.
You’d have to do an
===(or!==) against the list of accepted values (which wouldn’t be that long, from your question), being aware that that could be tricked into thinking something wasn’t a native that was (just from another window).But basically:
Edit Re my comment about things from other windows: Be aware that constructors from one window are not
===to constructors from another window (including iframes), e.g.:alerts “wnd.Array === Array? false”, because the
Arrayinwndis not the same as theArrayin your current window, even though both are built-in constructors for arrays.