On Feb 3, 11:37 pm, Tom Robinson <[email protected]> wrote:
> Is this expected, or a bug? Seems like a bug to me, but I couldn't
> find a bug in Bugzilla (possibly because Bugzilla search and I don't
> get along well).
>
>     js> printStuff = function(str) { print("value="+str+" typeof="+
> (typeof str)) }
>     ...
>     js> String.prototype.printStuff = function() { print("value="+this
> +" typeof="+(typeof this)) }
>     ...
>     js> a = "foo";
>     foo
>     js> printStuff(a);
>     value=foo typeof=string
>     js> a.printStuff()
>     value=foo typeof=object
>
> Same with Numbers and Booleans. My solution is to wrap "this" in a
> call to String, etc. Not sure if there's a better workaround.
>
> (Rhino 1.7 release 2 PRERELEASE 2008 07 28)
>
> Thanks,
>
> Tom

This is correct behavior. The difference is between the primitive
string and the String object. There's an implicit conversion from the
primitive string to the String object before methods can be called.
SpiderMonkey (and presumably other ECMA-compliant engines) also behave
this way.

--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to