[Javascript] typeof
Today i needed a way to check the real type of an object in javascript. Since typeof always returns 'object' for Date and Array objects, i needed a typeof routine that would return 'array' or 'date' (needed for json encoding). Here is a simple method to detect if an object is an Array instance or a Date instance:
function objectIsArray(o) {
if (o === null)
return false;
return o.constructor == (new Array).constructor;
}
The constructor function is always defined for arrays. Two functions return equal if and only if they're the same function.
function objectIsArray(o) {
if (o === null)
return false;
return o.constructor == (new Array).constructor;
}
The constructor function is always defined for arrays. Two functions return equal if and only if they're the same function.
4 Comments:
cred ca mergea si asa:
function objectIsArray(o) {
return o.constructor === Array;
}
By Anonymous, at 12:44 PM
viagra online uk buy viagra in canada viagra rrp australia buy viagra soft online sublingual viagra pharmacy viagra cheap viagra nz viagra mexico viagra strips generic name of viagra super viagra pro viagra for sale without a prescription viagra equivalent viagra no prescription
By Anonymous, at 4:45 PM
buy facebook likes
get facebook likes
http://www.roughstock.com/history/urban-cowboy#comments http://www.helloandroid.com/content/sony-ericssons-xperia-arc
buy facebook likes facebook likes buy facebook likes
because i'm scared to death. something popped up saying warning. and stuff about viruses and malware. and i dont know wat t odo cuz norton 360 expired a long time ago. and this is my aunt's computer. so i'm just scared of getting in trouble for this cuz i have been looking up porn. T-T
1000 facebook likes buy facebook likes [url=http://1000fbfans.info]buy facebook likes [/url] get facebook likes
By Anonymous, at 12:01 AM
Primitive Types
Conversions
Reference Types
Operators
Statements
Functions
Object Basics
Object-Oriented Terminology
Working with Objects
Types of Objects
By wdmtest, at 12:53 PM
Post a Comment
<< Home