There is a variable in my code that is sometimes one of the following:
- number,
- boolean
- line,
- regular expression,
- date of,
- An object with 0 or more "native" properties.
I want to check if this variable is an "elementary object". I define an "elementary object" as:
- number,
- boolean
- line,
- regular expression,
- date of,
or, in other words, an object that does not have its own properties defined by the developer.
Object.getOwnPropertyNames(obj).length === 0, ( " " ) "" . , Object.getOwnPropertyNames("test")
Chrome (46.0.2490.86 (64- ) Ubuntu 15.10) DevTools Firefox 42 Ubuntu 15.10, ["0", "1", "2", "3", "length"] ( Chrome) [ "length", "0", "1", "2", "3" ] ( Firefox).
, , " " , ? , .
! :-)
Update:
, , , - , - .
function isElementaryValue(x) {
return typeof x === "number" ||
typeof x === "boolean" ||
typeof x === "string" ||
x instanceof RegExp ||
x instanceof Date;
}