dhtml wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
>dhtml wrote:
>>On Feb 17, 4:58 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
mk83...@yahoo.com wrote:
anchors[ndx].onclick = function aname() {
Firebug still lists an anonymous function. Is there a way to assign a
name?
You have assigned a name with the above, but Firebug never shows the name.
That should not come as a surprise because a) the name is only locally
available (except in JScript) and b) functions don't have a certain name in
the greater context.
In Spidermonkey Functions absolutely do have a name:-
You miss the point. I have said that Functions do _not_ have a *certain*
name in the greater context. That really is basic knowledge:
>>var x = function y() {
console.log(arguments.callee.name);
};
x();
Result: y
See? Would you really expect the function to be displayed as `y' despite
the property that is referring to it has the name `x'?
It doesn't have a name x. x is a reference to a function.
*yawn*
To a Function object. I know. You miss the point again.
That function has a name property, with the value y.
In one implementation.
The name property reflects the function's identifier.
As an ECMAScript extension, it stores the name of a locally available property:
,-[ECMAScript Ed. 3 Final, section 13]
|
| NOTE The Identifier in a FunctionExpression can be referenced from inside
| the FunctionExpression's FunctionBody to allow the function to call itself
| recursively. However, unlike in a FunctionDeclaration, the Identifier in
| a FunctionExpression cannot be referenced from and does not affect the
| scope enclosing the FunctionExpression.
It is entirely possible to have more than one variable point to the
same function.
I know. That is exactly one of my points. You cannot expect Firebug to
display the name there.
>And what about
o.z = function y() {
console.log(arguments.callee.name);
returns false;
};
Would you then expect Firebug displaying `y' as well despite `o.z' refers to
a completely different Function object? Most certainly not.
The function that o.z points to has a name. The name is y. It seems to
me to be a natural expectation that function.name would return the
identifier of the function.
It would be nonsense for Firebug's DOM inspector to display the same name
for different Function objects just because they happen to have a locally
available property with the same name. For example, it would lead to all
kinds of confusion if an object had
o.onclick = function x() { return true; };
o.onmouseup = function x() { return false; };
and Firebug's DOM inspector were to display
onclick x()
onmouseup x()
instead of what it currently displays:
onclick function()
onmouseup function()
The name property of a Function object, if it has one, is completely
irrelevant outside its local execution context.
It also is a good idea to give a meaningful and unique name to the
function.
It is in a function declaration, not in a function expression.
Of course, the problem with adding an identifier is that old
JScript bug.
Therefore, it is not a good idea.
There's also been some bugs in versions of Safari as recent as 2.
Therefore, it is an even worse idea.
>>As for the problem of inspecting the LI, logging it should have the
effect:
console.log( li );
That will of course display only the start tag of the element, a string
representation of the element node and its attribute nodes.
That is what clicking on it is for.
Have you ever done that for an object that has an event listener added?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>