Both firefox’s js engine/gjs (spidermonkey) and webkit’s jscore seems to have different behavior when calling builtin and normal js functions on non-object.
gjs> toString.call(null)
"[object Null]"
gjs> function cccc() {return toString.call(this);}
gjs> cccc.call(null)
"[object GjsGlobal]"
So if a normal js function is called with non-object, its this is automatically get replaced by the current this, whereas this won’t happen for a builtin function.
Is this the standard behavior (according to some specification?) or is it just a implementation dependent behavior?
Is the first line always safe to check the type of any value?
THX
That behaviour is by design. As noted in the Mozilla documentation:
Apparently, builtin functions are (treated as) strict mode code. Your own functions are not, unless, of course, you write a strict mode function. 🙂
This will be different in ECMAScript 5. From the specification (PDF):
Here’s a more direct link to a non-normative but HTML version of the spec.