473,806 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

arguments.calle e.name vs. functionName.na me?

What in the world is functionName.na me good for? That is:

function functionName() { return functionName.na me; }

I mean, I already had to write out the function's name so it seems that it is not very
useful or efficient.

To me, this.name seems most appropriate, but of course that does not work within the
context of a function unless defined as a class, which of course then the name property
does not apply to the calling function.

Of course, you could always assign it yourself like:

function functionName() { this.name = arguments.calle e.name; }

But anyway... my original question, what is the purpose of using functionName.na me as
opposed to arguments.calle e.name? (The second being useful, efficient and dynamic.)

Thanks.

-Lost
Jan 27 '07 #1
12 3487
VK
What in the world is functionName.na me good for?

Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.

Similar functionality can be emulated cross-UAs though by using
toString/parsing if toString is not overriden. So if put theoretically
as "would be such property useful if available?" then yes - sometimes;
say for serializations.

Jan 27 '07 #2
"VK" <sc**********@y ahoo.comwrote in message
news:11******** **************@ v45g2000cwv.goo glegroups.com.. .
>What in the world is functionName.na me good for?

Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.
Oops, I guess I missed that part. I was desperate to find a way to get *just* the
function name instead of the entire load that arguments.calle e returns.

I found out that attempting to snag some of the data via substring was not going to work.
When I ran across that in the Core JS 1.5 reference I thought it would be the definitive
solution.
Similar functionality can be emulated cross-UAs though by using
toString/parsing if toString is not overriden. So if put theoretically
as "would be such property useful if available?" then yes - sometimes;
say for serializations.
What is a "UA"?

-Lost
Jan 28 '07 #3
VK wrote:

Hi,
>What in the world is functionName.na me good for?

Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.
Agreed for the cross-browser argument, however were 'function.name'
available to other user agents, would the conclusion still remain : it
is, by essence, a useless feature in (modern) javascript.

When conceptualizing functions, one should consider that they are by
nature anonymous objects, which can be bound to zero or many named
properties of any object. In other words, functions can be anonymous
(not even declared on some named property), or have several "names".

The approach of manipulating functions by their name generally indicates
that the programmer is not aware that functions are first-class objects
in javascript; his/her scripting approach is incomplete and generally
results in some complicated and unnatural production.

<URL:http://en.wikipedia.or g/wiki/First-class_object>
<URL:http://en.wikipedia.or g/wiki/First-class_function>

Similar functionality can be emulated cross-UAs though by using
toString/parsing if toString is not overriden.
function funcName(func){
var p=/function\s+(\w+ )/.exec(func+"");
return p?p[1]:null;
}

.... was the code Gosha Bine proposed in his late func.js.
So if put theoretically
as "would be such property useful if available?" then yes - sometimes;
say for serializations.
Serialization is the process by which you transform some 'live' object
or execution context into some bytes or text, so that it can be saved
and/or safely transmitted to other programs. Inflating the serialized
code then permits to resume the execution.

In javascript, functions names would not be used in some serialization
process, because not only has the name nothing to do with the function's
object identity, but also nothing to do with the function object itself
(the name related to the object to which it belongs as a named property).
Regards,
Elegie.
Jan 28 '07 #4
-Lost wrote:
What is a "UA"?
That would be an User Agent, a.k.a browser.

--
Osmo
Jan 28 '07 #5
Osmo Saarikumpu <os**@weppipakk i.comwrote:
>What is a "UA"?

That would be an User Agent, a.k.a browser.
A browser is a UA, but not all UAs are browsers. Any application that
can process HTML is a HTML UA, for example a SE bot, a validator etc.

--
Spartanicus
Jan 28 '07 #6
"Spartanicu s" <in*****@invali d.invalidwrote in message
news:00******** *************** *********@4ax.c om...
Osmo Saarikumpu <os**@weppipakk i.comwrote:
>>What is a "UA"?

That would be an User Agent, a.k.a browser.

A browser is a UA, but not all UAs are browsers. Any application that
can process HTML is a HTML UA, for example a SE bot, a validator etc.

--
Spartanicus
Thanks you two.

-Lost
Jan 28 '07 #7
On Jan 27, 10:05 pm, "-Lost" <spam_ninjaREMO V...@REMOVEMEco mcast.net>
wrote:
What in the world is functionName.na me good for? That is:

function functionName() { return functionName.na me; }

I mean, I already had to write out the function's name so it seems that it is not very
useful or efficient.
You forget that functions are objects in JS; you can assign them to
variables, pass as parameters to arguments.
To me, this.name seems most appropriate, but of course that does not work within the
context of a function unless defined as a class, which of course then the name property
does not apply to the calling function.

Of course, you could always assign it yourself like:

function functionName() { this.name = arguments.calle e.name; }
Ugh, it looks like you should read about |this|. The JS reference on
developer.mozil la.org has good articles about it.
But anyway... my original question, what is the purpose of using functionName.na me as
opposed to arguments.calle e.name? (The second being useful, efficient and dynamic.)
arguments.calle e is a function, so arguments.calle e.name invokes the
same code that functionName.na me. Of course getting the function name
via .name when you already know it doesn't make any sense.

Nickolay

Jan 30 '07 #8
On Jan 28, 1:46 pm, Elegie <ele...@invalid .comwrote:
VK wrote:Hi,
What in the world is functionName.na me good for?
Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.
Agreed for the cross-browser argument, however were 'function.name'
available to other user agents, would the conclusion still remain : it
is, by essence, a useless feature in (modern) javascript.

When conceptualizing functions, one should consider that they are by
nature anonymous objects, which can be bound to zero or many named
properties of any object. In other words, functions can be anonymous
(not even declared on some named property), or have several "names".
Wrong - function may or may not be anonymous. Though, you're right
that the 'name' of the function has nothing to do with the variable or
property it is assigned to.

In Mozilla source you can often see declarations like this:
var obj = {
//...
method1: function obj_method1() {
}
};

...which creates a named function 'obj_method1' and assigns it to
obj.method1. Now while is it true that one could assign the same
function to another property on another object, like so:
obj2.anotherMet hod = obj.method1

...in reality this is seldom done (for certain kinds of functions
anyway).

Giving names to functions in such a way is useful for debugging:
* you can print sensible names in stack traces
* I believe Venkman uses function names when printing profiling data.
* When you want to add logging to a function that takes a function as
a parameter.
and so on.
In javascript, functions names would not be used in some serialization
process, because not only has the name nothing to do with the function's
object identity, but also nothing to do with the function object itself
(the name related to the object to which it belongs as a named property).
Either I misunderstood you or you are wrong. The function name
obviously has to do with the function object itself.

Nickolay

Jan 30 '07 #9
Nickolay Ponomarev wrote:

Hi,

[In all this discussion I will be referring to the ECMAScript
specification, chap. 13, which describes accurately how functions work
in javascript]
>When conceptualizing functions, one should consider that they are by
nature anonymous objects, which can be bound to zero or many named
properties of any object. In other words, functions can be anonymous
(not even declared on some named property), or have several "names".
Wrong - function may or may not be anonymous. Though, you're right
that the 'name' of the function has nothing to do with the variable or
property it is assigned to.
I'm afraid we do not understand each other. Let me rephrase my
statement: in javascript, functions have no name, and using the
expression "function's name" is by nature incorrect, some kind of
language abuse, which may be useful, but also may slow down the
programmer in understanding that functions are first-class objects.

The thing is that what is perceived as the 'name' of the function is
generally (see below for the exception) the name of the property to
which this function is bound. Consider the following productions
(ECMA262 13).

---
function foo(){}
---

---
var bar=function(){ }
---

According to the specification (excluding function joining issues), this
statement creates a function object (ECMA262 13.2), then creates a
property on the current Variable Object (be it the Global Object or some
Activation Object), then assigns the function to this named property. In
itself, the function has absolutely no name, it is simply some anonymous
callable object attached to the 'foo'/'bar' property of the Variable Object.

The only exception to this algorithm concerns the production
[FunctionExpress ion : function Identifier], which you have indeed used
as an example in your post. This pattern inserts an anonymous object in
the function's scope chain, with the identifier being defined as the
only property of this object; this results in the function being able to
call itself recursively (the identifier does not leak outside, as per
scoping rules).

Your considering this identifier as the function name does probably no
harm as long as you are aware of the exceptional aspect of this pattern,
but note that it is never used in cross-browsers projects, for IE does
not respect the ECMA specification with the quoted scoping rule.

This is getting rather theoretical, so to illustrate the whole point I
would like to ask the question: is the following examples, what is the
'name' of the function?

---
var foo=function(){ }
var bar=foo;
---

or

---
function foo(){}
var bar=foo;
---

or

---
var foo=function bar(){}
---

or

---
(function(){
alert("Hello, World !");
})();
---

<snip>
Giving names to functions in such a way is useful for debugging:
* you can print sensible names in stack traces
* I believe Venkman uses function names when printing profiling data.
* When you want to add logging to a function that takes a function as
a parameter.
and so on.
I agree of course, I'm not arguing against defining an identifier in a
function at all :)

By the way, coding practices should not be adopted because of
tools/debuggers capabilities, but because it fits the paradigm of the
language (at first).
>In javascript, functions names would not be used in some serialization
process, because not only has the name nothing to do with the function's
object identity, but also nothing to do with the function object itself
(the name related to the object to which it belongs as a named property).
Either I misunderstood you or you are wrong. The function name
obviously has to do with the function object itself.
The only case when this matters is the FunctionExpress ion pattern, with
some defined identifier, as described above.

Also, serialization is a process in which an object's identity is
fundamental; a function 'name' as you see it, if optional, could
therefore not be used as identity trait, but rather as an informative
property. The following is perfectly valid in javascript, with
absolutely no name collapsing:

---
var bar1=function foo(){}
var bar2=function foo(){}
---

Regarding serialization is javascript, my statement was somehow purely
theoretical though, given the scoping rules some appropriate process
would probably include the whole global execution context.
Regards,
Elegie.
Jan 30 '07 #10

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

Similar topics

12
2811
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of function descriptors for the overloaded functions of that name. A function descriptor would contain the address of the function to be called, and a description of the parameters that it must take. b. A list of parameters. This would be compared to the...
9
3346
by: Robert | last post by:
Hi, Currently I am using argument.callee.caller.arguments to get the arguments of the caller function, but Firefox complains that arguments (of Function) is deprecated. Is there a way to get the arguments of the calling function in a non-deprecated way?
41
2593
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum += arguments;
9
16849
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script type='text/javascript'> function myFunc(lev) { // if (lev) return myFunc(lev-1); var aStack=; nextFunc = arguments.callee;
7
1944
by: sfeher | last post by:
Hi All, Is there a way to preserve the arguments across functions? I have: <script> function myFirstFunction() { // arguments = 'param1'
7
1792
by: runsun pan | last post by:
I wanna check if an object is the *arguments* object of a function, is that possible? When we do: typeof(arguments) it always returns "object", doesn't seem to be helpful.
7
3228
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
34
4523
by: Jorge | last post by:
Why is it listed here : http://www.crockford.com/javascript/recommend.html under "deprecation" ? Without it, how is an anonymous function() going to call itself (recursively) ? I use to write timers like this :
3
475
by: lancer6238 | last post by:
Hi, I was looking at an open-source program and saw a function header defined as: int Function(int value1, int value2, (int *A)(void *A1, int *A2, void *A3), void *A3) and the function is called by
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.