I've been using the same JavaScript library I've built for years, and now I'm encountering errors with this function:
IsArray : function ()
{
if (typeof arguments[0] == 'object')
{
var criterion = arguments[0].constructor.toString().match(/array/i);
return (criterion != null);
}
return false;
}
There are times when it is called when the following error is thrown:
TypeError: Cannot call method "toString" of undefined
I added the following prior to defining the criterion variable to remedy the issue:
if (arguments[0].constructor == null || arguments[0].constructor == undefined)
return false;
However, I'd like to understand how or why this would happen. I don't know why a variable that has a type of 'object' would not have a constructor. I've never seen it prior to this issue. And what bothers me about this is this all started a few weeks after I updated another library function that checks for nulls and empty strings to try to filter out empty arrays (when comparing an empty array to an empty string, it was returning a match).