The what:
test
only takes strings as input, so a function will be toString
ed, like will any other object that's not a string. xyz
is not interpreted as a variable, but as a string, so it won't throw a reference error. This happens in other places as well, take this for example:
var a = function(){}; var b = function(){};
console.log(a + b); // `+` coerces with `toString`
The why:
The serialization of functions in old browsers is not reliable and might not output the _super
property in the function's body, but (I'm assuming) something like function{[native code]}
or [object Object]
; in those cases use a regex such as /.*/
to match anything and not perform the optimizations that can be done in browsers that output the correct result.
Related links for more info:
http://blog.buymeasoda.com/understanding-john-resigs-simple-javascript-i/ (found by Andreas)
http://es5.github.io/x15.3.html#x15.3.4.2
http://bytes.com/topic/javascript/answers/747203-function-tostring