Hi,
I am trying to complete the implementation of the String stdlib functions. I hit a small roadblock that has me puzzled. Consider the following code:
// ---- var s = "abc";
function f(x) { if (s === this) print("global = this"); if (x === this) print("arg = this"); if (x === s) print("arg = global"); }
String.prototype.f = f; s.f(s); // ----
The code only prints the last string (arg = global) when run with d8. The only explanation I can see is that using a string value (typeof s === 'string') as the receiver of a call (and thus the implicit 'this' parameter) converts it to a string object (typeof this === 'object'). Can somebody point me to the part of the ECMAScript spec that explains this behaviour? I may be blind, but I can't seem to find it...
Thanks,
Bruno