Subj : Inconsistent function behavior in Rhino To : netscape.public.mozilla.jseng From : barnabas.wolf@mssm.edu (Barnabas Wolf) Date : Fri Jan 24 2003 10:02 am Hello, Consider the following example: var obj = { a: "aaa", print: function(name) { writeln("this[name]: "+this[name]); writeln("this[String(name)]: "+this[String(name)]); }, other_func: function() { this.print("a"); } } writeln("print function declered in object: "); obj.print("a"); The above code will print "aaa" for both this[name] and this[String(name)] (assuming an obvious implementation for writeln). "other_func" has no purpose here, except to contrast the code with the following way of declaring the same object: function print(name) { writeln("this[name]: "+this[name]); writeln("this[String(name)]: "+this[String(name)]); }; function breakobj2() { this.print("a"); }; var obj2 = { a: "aaa", print: print } writeln("print declerated externally, referenced in object: "); obj2.print("a"); In this version this[name] is *undefined* while this[String(name)] is fine. The presence of a reference to the print function (in breakobj2) is what appears to break the code. Note that breakobj2 does not even need to be part of obj2. If any function is declared with a possible reference to print, then this[attribute_name] does not work in print without an explicit typecast to a string. What could cause this? Is there an easy fix or a workaround? I am porting a considerable amount of code from FESI to Rhino, and I would like to avoid rewriting the object/function declerations in the process... :) Any help or suggestions will be greatly apprciated. Barnabas .