473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Re: anonymous functions; naming of and firebug

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:-

var x = function y() {
console.log(arguments.callee.name);
};

x();

Result: y

As for the problem of inspecting the LI, logging it should have the
effect:

console.log( li );
Garrett

[snip]
PointedEars
Jun 27 '08 #1
5 1743
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'?

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.
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. Since `onclick'
is an attribute in the markup but not accessed as such here (else you would
assign a string value and not a Function object reference), there is no
change in its representation. (If one used setAttribute(), the change would
be visible in Firebug, but the script would not be likely to work everywhere.)
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>
Jun 27 '08 #2
On Apr 14, 12:24 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
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. That
function has a name property, with the value y. The name property
reflects the function's identifier.

It is entirely possible to have more than one variable point to the
same function. For example:

var a = [], z;
z = a[0] = function y(){};

I would not expect the function's name to be a[0].

>
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 also is a good idea to give a meaningful and unique name to the
function. Of course, the problem with adding an identifier is that old
JScript bug. There's also been some bugs in versions of Safari as
recent as 2.
>
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.

Since `onclick'
is an attribute in the markup but not accessed as such here (else you would
assign a string value and not a Function object reference), there is no
change in its representation. (If one used setAttribute(), the change would
be visible in Firebug, but the script would not be likely to work everywhere.)


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, <f806at$ail$1$8300d...@news.demon.co.uk>
Jun 27 '08 #3
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>
Jun 27 '08 #4
dhtml <dh**********@gmail.comwrites:
> o.z = function y() {
....
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.
That would have been a reasonable design. Alas, it isn't so. There
is no direct way to access that name from outside its scope. Its
scope is the body of the function.

On the other hand, it's also completely useless outside of its scope,
for anything but documentation purposes, so it's no big loss in
practice.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 27 '08 #5
On Apr 16, 3:07*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
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() {

The spec does not contain a - name - property for a function object.
It's there in Spidermonkey.
>
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 works in Spidermonkey. When I try this in Firebug, I can see that
the name - y - will get printed out. It's possibly a different version
of Firebug.

document.body.onclick = function y(){};
document.body

This displays in Firebug:
"<body>"

When I click on that <body>, then choose the right-side DOM tab, I can
see
onclick y()

For me, that makes it easier to debug.

It's possible that I could have two functions with y, but I would
probably not do that. If I did, I'd still ahve it narrowed down to two
functions in the search result.

>
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, <f806at$ail$1$8300d...@news.demon.co.uk>- Hide quoted text -

- Show quoted text -
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
60
by: jacob navia | last post by:
Gnu C features some interesting extensions, among others compound statements that return a value. For instance: ({ int y = foo(); int z; if (y>0) z = y; else z=-y; z; }) A block enclosed by...
1
by: szako szako | last post by:
I experienced the same, firebug doesn't show event changes linked to objects in html source... *** Sent via Developersdex http://www.developersdex.com ***
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.