473,779 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getFunctionName v1.0

VK
And this script supposes to work everywhere. It allows to get the name
of any function from within the function itself.

<html>
<head>
<title>Functi on name</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script type="text/javascript">

function test() {
var myName = getFunctionName (arguments.call ee);
alert(myName);
}

function getFunctionName (f) {
var tmp = f.toString();
var re = /(\s*function\s+ )(\w+)(\s*\()/m;
re.exec(tmp);
return RegExp.$2;
}

</script>
</head>

<body bgcolor="#FFFFF F" onload="test()" >

</body>
</html>

Jul 25 '05 #1
34 2132
In the past I have found that approach does not work for anonymous
functions (by definition!).

var anon=function()
{
var myName = getFunctionName (arguments.call *ee);
alert(myName);
};

anon();

Jul 26 '05 #2
VK


Baconbutty wrote:
In the past I have found that approach does not work for anonymous
functions (by definition!).

var anon=function()
{
var myName = getFunctionName (arguments.call *ee);
alert(myName);
};

anon();


But how does it suppose to work for anonymous functions? Anonymous
functions do not have names, this is why they are anonymous!
getFunctionName will return in such case the string "anonymous" , and
it's holly truth.
I could change it into some getNameOrNameIt , so it would clone
anonymous functions on the spot and give them names, but it would be
the whole new story. And why?

Jul 26 '05 #3
>But how does it suppose to work for anonymous functions? Anonymous
functions do not have names, this is why they are anonymous!
That is the point that I was making.

And it can never work because more than one variable could hold a
reference to the anonymous function. Some people do get confused with
that.
And why?


See my notes on serialisation to your other post.

Jul 26 '05 #4
VK


Baconbutty wrote:
But how does it suppose to work for anonymous functions? Anonymous
functions do not have names, this is why they are anonymous!


That is the point that I was making.

And it can never work because more than one variable could hold a
reference to the anonymous function.


Never say never possible!
It's the first rule of every web-development victim :-)

But what situation are you conserned about? I'm just a bit cloudy here.

What anonymous functions can stop you from serialization? Intrinsic
event handlers or custom objects' methods? I don't see any other
*valid* reasons to have anon functions. Or yeh, and runtime assemply
using Function() but it's ugly and I did not see it in a wide use.

Could you give some code like "this and that, and here we have to stop
because..." ?

Jul 26 '05 #5
JRS: In article <11************ **********@g14g 2000cwa.googleg roups.com>
, dated Mon, 25 Jul 2005 13:43:23, seen in news:comp.lang. javascript, VK
<sc**********@y ahoo.com> posted :
And this script supposes to work everywhere.
It does not work for me as posted, using IE4.

<body bgcolor="#FFFFF F" onload="test()" >


One should not set a background colour with an unknown foreground
colour, not vice versa.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 26 '05 #6
VK
Dr John Stockton wrote:
It does not work for me as posted, using IE4.


Edit me if I'm mistaken but IE4 (Oct. 1997) is out of the scope of
support in the year 2005, as well as NN4.
BTW: IE3.1 was released just one year earlier (Oct. 1996), so why
wouldn't include it also?

Actually IE5 (Mar. 1999) should be forgotten by all means too (6 years
is the age of dinosaurs for browsers). It remains a bizarre exception
because in 6 years and till now Macintosh did not manage to produce ane
decent browser for their OS. So we semi stoke with this ancient product
when a maximum compatibility is needed.

IE5.5 (Jul. 2000) is really a border line. After all Windows users will
finally migrate on XP SP2 (no latter than the end of this year), we can
forget this twilight product with the greatest relief.

Jul 26 '05 #7
D
"VK" <sc**********@y ahoo.com> writes:
After all Windows users will finally migrate on XP SP2 (no latter
than the end of this year), we can forget this twilight product with
the greatest relief.


Unless Microsoft starts giving XP away for free, I think it's highly
unlikely that home users will be more likely to upgrade then than now.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 26 '05 #8
VK wrote:
Edit me if I'm mistaken but IE4 (Oct. 1997) is out of the scope of
support in the year 2005, as well as NN4.
Why? Because you say so?

Different people have different requirements. I know a number of situations
where NN4 support is still required, and at least several where IE4 support
is required.

It all depends.
After all Windows users
will finally migrate on XP SP2 (no latter than the end of this year),
we can forget this twilight product with the greatest relief.


MANY corporate users are still on Windows 2000, with no plans to migrate to
XP.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 26 '05 #9
On 26/07/2005 18:59, VK wrote:
Dr John Stockton wrote:
It does not work for me as posted, using IE4.
Edit me if I'm mistaken but IE4 (Oct. 1997) is out of the scope of
support in the year 2005, as well as NN4.


There are different degrees of support. Expecting browsers of that
generation to be capable of the same things as current browsers is
unrealistic, and on that basis it's fair to exclude them. However, that
doesn't mean code should fail uncontrollably, causing errors or, in the
worst case, crashing the browser.
BTW: IE3.1 was released just one year earlier (Oct. 1996), so why
wouldn't include it also?


IE3 is /significantly/ less capable than IE4 and, though IE4 is
relatively rare, IE3 is non-existent.

[snipped tangent]

As for IE4 compatibility, remove the multi-line flag. You don't need it
anyway.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 26 '05 #10

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

Similar topics

3
25096
by: Daniel Hansen | last post by:
I'm sure I saw this somewhere but can't remember where and can't find it now... Is there a PHP function or global variable that will return name of the calling function? I want to do this for error reporting purposes without having to hardcode the function name into my scripts. Say the function is named getFunctionName(). I want to do something like... function foo() {
6
6079
by: Richard Berg | last post by:
Hello, I need implementation advice: I am writing a program that should call some API functions in a specific order. The APIs are for another application, not Windows APIs. The order and type of the calls is determined at runtime. There are a couple of hundred of those APIs that can be called, and they all take different parameters. What I need is somehow queue the calls with their parameters and then dequeue and execute them one by...
4
3820
by: Hrvoje Voda | last post by:
How to get a list of names from database into string array? variable name should be string array... This is the code I use... public string GetFunctionName(Guid UserID) {
0
9474
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
10306
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...
1
10075
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
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6727
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();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.