Simon Willison’s Weblog

Subscribe
Atom feed for instanceof

1 item tagged “instanceof”

2009

instanceof considered harmful (or how to write a robust isArray. JavaScript’s instanceof operator breaks when dealing with objects that may have been created in a different document or frame, since constructors are unique to each frame. Instead, you can check for arrays using the default Object.toString method which the JS spec guarantees will return [object Array].

# 12th January 2009, 10:55 am / arrays, javascript, instanceof, tostring, frames