Servus Ninjas,
this is what ecmascript 5 spec. (page 118) in the section Function.prototype.apply(thisArg, argArray) says:
NOTE: The thisArg value is passed without modification as the this value. This is a change from Edition 3, where a undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value.
This sounds promising, but this spec isn’t implemented yet in any of the modern browsers so we have to deal with the 3rd spec implementation.
My question now is „How to get the typeof statement become TRUE?“
var foo = function (arg1, arg2) {
alert(typeof this == "string");
};
foo.apply("bar", ["arg1", "arg2"]);
any ideas?
Either use
this instanceof String(same window-only) or useObject.prototype.toString.call(this) === "[object String]"(works across windows).