A growing trend (IMO) in JavaScript is to use objects for namespaces. However, when an object constructor is an attribute of an object, the Function.toString() method thinks its an internal function. For example, this code: var Foo = {}; Foo.Bar = function () { this.bar = 1; }; var f = new Foo.Bar(); document.write(Function.toString.call(f.constructor)); Outputs "(Internal Function)" in Safari and "function () { this.bar = 1; }" in Firefox. Can Safari be updated to output the same string as Firefox?
Actually, looking more closly at it, I realize that the problem is not the stringification of the constructor of an object created in a class that uses objects for namespaces. The problem is that Function.constructor() returns the wrong function object! var Foo = {}; Foo.Bar = function () { this.bar = 1; }; var f = new Foo.Bar(); document.write(Function.toString.call(f.constructor)); Again, this outputs "(Internal Function)" because the return value of f.constructor is not the actual constructor function. I have no idea what function it's returning. Thanks!
> Function.constructor() returns the wrong function object! Uh, make that the constructor attribute of the object has the wrong object.
Here's a simpler test case: var Foo = { Bar: function () {}}; var f = new Foo.Bar(); document.write(f.constructor == Foo.Bar); This code outputs true in Firefox, but false in Safari. It should output true.
I'll add the testcase in the comment below as a real testcase, please do so next time you post a bug :). And i will confirm it, since the behavior IS different from firefox and some will have to look in to it.
Created attachment 2347 [details] testcase
Created attachment 4069 [details] Test case showing broken nameless function support.
*** Bug 4042 has been marked as a duplicate of this bug. ***
Created attachment 4071 [details] A small patch to fix this.
I suggested to Eric that he also test the case of the Function constructor.
Comment on attachment 4071 [details] A small patch to fix this. r=me Make sure to make the test case also cover the new Function() case.
Shouldn't the first example in the test case also evaluate to true?