When I do: typeof([]) it returns object.
I've heard its not really acceptable to edit the prototypes of JavaScript's inbuilt types.
However, if I do this: Array.prototype.isArray = true; and then the following work:
var arr = [];
var obj = {};
if (arr.isArray)
{
console.log("Array");
}
else
{
console.log("Not array");
}
if (obj.isArray) // undefined
{
console.log("Array");
}
else
{
console.log("Not array");
}
Or is this still not acceptable? What would be a better way around this?
No comments:
Post a Comment