This one just stabbed me hard. I don\'t know if it\'s the case with all browsers (I don\'t have any other competent browser to test with), but at least Firefox has two kind
Another important thing to remember is the following:
typeof "my-string" // "string"
typeof String('my-string') // 'string'
typeof new String("my-string") // "object".
Therefore, when testing whether an argument or variable is a string you need to do at least the following.
function isString(arg) {
if (!arg) {
return false;
}
return typeof arg == "string" || arg.constructor == String;
}
The above function will still fail if you pass in a String object from another frame/iframe. That is:
frames[0].myStringVar.constructor != frames[1].myStringVar.constructor
That is because the constructor String is different for each window context. Therefore, a foolproof isString method would be
function isString(obj) {
return Object.prototype.toString.call(obj) == "[object String]";
}