Comment #4 on issue 838 by swivelgames: Function [[Call]] should return
Reference Type
http://code.google.com/p/v8/issues/detail?id=838
But is it safe to say that, theoretically, a function *could* return a
reference? Like, in the example below...
var myObj = new Object();
function myFunc() {
myObj.test = "blah";
return myObj;
}
myFunc() = new String("foobar");
Shouldn't `myObj` now become a primitive string called "foobar"? Afterall,
the engine treats variables in JavaScript more like reference holders than
actual variables. This seems like it would be proper JavaScript....
Especially since the following is valid...
myFunc().test = "rawr";
console.log(myObj.test); // Prints out "rawr"
This early error is actually in violation of both Early Errors but also
Section 8.7, "The Reference Specification Type"
(http://es5.github.com/#x8.7)
Technically the first example I gave is completely legal, although it is
only a side-affect of the intended capabilities. Still, it is clearly
written that it is indeed a side-affect but does indeed need to function
that way. Just as chainability has spawned from this very ability, the
first example is clearly legal. It is only limited due to the Early Error
implemented in the engine. Otherwise, technically, the first example should
work.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev