Closed Bug 1048436 Opened 12 years ago Closed 12 years ago

Web Console logs anonymous function in array as "myArray<()"

Categories

(DevTools :: Console, defect)

33 Branch
x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: fvsch, Unassigned)

Details

This code: var myArray = [ function (){}, function test(){} ]; console.log(1, myArray); console.log(2, myArray[0]); console.log(3, myArray[1]); console.log(4, [function(){}]); Displays: 1 Array [ myArray<(), test() ] 2 function myArray<() 3 function test() 4 Array [ function () ] The "<" in "myArray<" seems to be a bug. One would expect: 1 Array [ function (), test() ] 2 function () 3 function test() 4 Array [ function () ]
Console logs the name of the function. When a name is missing, Spider Monkey generates a name for it. myArray<() means a no named method inside of an object named myArray displaying "function () {}" in such cases might lead to confusion like "Is function the name of the function ? " For example, take this series of logs < var b = { foo: function bar() {}} > undefined < b.foo > function bar() < b > Object { foo: bar() } < b.foo = function () {} > function b.foo() < b > Object { foo: b.foo() } See that the first time, a name "bar" was present, so it displayed { foo: bar() }, while after I made foo as a no named function, it picked the name as given by Spider Monkey, which, although in this case was more meaningful as the key "foo" was present. For an array, what can be done is to use the index of the function as the text after the "<".
Thanks for the report, but statically inferred names for anonymous functions is actually a feature! See bug 433529 for more details.
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
Thanks for the info. Glad to know that it works as intended. I’ll still point out that the "a<" notation is not intuitive, as stated in bug 433529: > a< - flags a "contributor" or basically some helper function which contributes > to the function named 'a' by being anonymous inside it. This is kinda > odd and is one I wouldn't mind dropping or enhancing. But since I don’t have a better one to offer, I’ll leave this bug RESOLVED. It’s a usability bug to some extent, but declaring an anonymous function as an array member is not a common pattern (as far as I know).
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.