473,791 Members | 2,816 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
34 2135
VK
> You're a PERL guy, right? Garbage collection in JS works just like
PERL's.
I had to work a lot with Perl during The Bubble, but it was a "forced
marriage" (good contract = CGI = Perl).
Personally I think it was a language the least suited for Web. Just one
of the Bubble's twists: it was available, it was semi-working, it was
free and opps... it's a world wide standard.

The memory issues never bothered me there as I knew Perl only from its
CGI-script side. And on each shared server there was a "serial object
killer" launched by admin. After the assigned deadline it would simply
kill your context no matter was it in use or trach leftovers. So the
task was to do it as quick as possible and get out :-)

Whenever a variable's internal reference count reaches 0, it is
considered disposable and is disposed of.

The following lines do the exact same thing in JS as they do in PERL
(copy/paste them if you want):
$x = { };
$y = $x;
$x = { };
$y = { };

They differ only in that in JS { } is an object literal, and in PERL {
} is a hash literal, but that's immaterial to this discussion.

The thing created on line 1 is not garbage collected until line 4, and
it will ALWAYS be garbage collected at line 4. You can depend upon it.
There is no mystery to when an object is disposed of.

It is disposed of when the number of references to it reaches zero.
Plain and simple. No 'eventually' about it.

Period.


That's a great piece of info if you really sure about it!

Still I cannot understand why would anyone need two co-existing
references to the same object in the same namespace. For sport? To
check the garbage collector? JavaScript fully supports object
construction, extention and inheritance. If you really want to stay
within OP that would be plenty enough.

Jul 28 '05 #31
JRS: In article <11************ *********@g43g2 000cwa.googlegr oups.com>,
dated Wed, 27 Jul 2005 13:05:05, seen in news:comp.lang. javascript, VK
<sc**********@y ahoo.com> posted :
Lines: 39

Being a regular reader of this group, you should have known that IE4 is
still in use.


As well as


.... irrelevant waffle.
Everywhere means everywhere; you were wrong; your advice cannot be
relied upon.


Oh com'on... Read the linked topic.


The fact remains that you made a false statement, either by intention or
by carelessness. Your code did not work everywhere, not even in all
javascript browsers in current use.

--
© John Stockton, Surrey, UK. ??*@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jul 28 '05 #32
"VK" <sc**********@y ahoo.com> writes:
engine (because you twisted its brains off). Good if it's some Object()


You know, it was only through a great deal of restraint that I prevented
myself from spraying my keyboard with soda after the "trashhold" thing,
then you have to go and write about twisting a GC's brains off! Now
look at the mess I have!

--
Jason Dufair - ja**@dufair.org
http://www.dufair.org/
Crazy just thinkin' knowing that the world is round
And here I'm dancing on the ground
Never right side up or upside down
Is this real or am I dreaming?
-- Dave Matthews Band, "Crush"
Jul 28 '05 #33
VK
Jason Dufair wrote:
You know, it was only through a great deal of restraint that I prevented
myself from spraying my keyboard with soda after the "trashhold" thing,
then you have to go and write about twisting a GC's brains off! Now
look at the mess I have!


<FLUD>
It's just nothing. But if you see a thread here about *class* or *hash*
you better read it without a coffee in your hand or some unexpected and
painful physical damage is nearly guaranteed.
</FLUD>

Jul 28 '05 #34
VK wrote:
You're a PERL guy, right? Garbage collection in JS works just like
PERL's.
I had to work a lot with Perl during The Bubble, but it was a "forced
marriage" (good contract = CGI = Perl).
Personally I think it was a language the least suited for Web. Just one
of the Bubble's twists: it was available, it was semi-working, it was
free and opps... it's a world wide standard.


No oops about it... if you need fast code, do C. If you need code fast,
do PERL.
The memory issues never bothered me there as I knew Perl only from its
CGI-script side.
In which memory issues can and often are far more prevalent.
And on each shared server there was a "serial object
killer" launched by admin. After the assigned deadline it would simply
kill your context no matter was it in use or trach leftovers. So the
task was to do it as quick as possible and get out :-)
Isn't it always?
Whenever a variable's internal reference count reaches 0, it is
considered disposable and is disposed of.
$x = { };
$y = $x;
$x = { };
$y = { };

The thing created on line 1 is not garbage collected until line 4, and
it will ALWAYS be garbage collected at line 4. You can depend upon it.
There is no mystery to when an object is disposed of.

It is disposed of when the number of references to it reaches zero.
Plain and simple. No 'eventually' about it.

Period.


That's a great piece of info if you really sure about it!


Technically it becomes "available for disposal". In practice the engine
might dispose of it in a few nano- or micro- seconds. By spec I believe
it is *allowed* to wait until it's damned good and ready, but the point
is that after the object's internal reference count reaches 0 it
becomes unreferrable and it *will* certainly be garbage-collected.

There are certainly ways to defeat this if you want to, but garbage
collection is fairly well-defined and dependable, and you can predict
what will be disposed of if you understand what you're coding.

*IF* you understand what you're doing.

Something we should all strive for, yes?
Still I cannot understand why would anyone need two co-existing
references to the same object in the same namespace. For sport? To
check the garbage collector? JavaScript fully supports object
construction, extention and inheritance. If you really want to stay
within OP that would be plenty enough.


For simplicity, efficiency, maintainability , readbility, and plain
elegance of code.

Consider this:

var c = 0,
things = [
new Thing(1),
new Thing(2),
// ...
new Thing(20)
];
/* the next statement creates a second reference to an existing object
* that already has a reference stored in the things[] array.
*/
while( thing = things[ ++c ] ) {
// figure out some x and y coords
thing.position( x, y );
thing.show();
}
Almost any time you need to perform multiple operations on an arbitrary
object independent of its name, it doesn't make sense but to store a
second reference to it.

Why wouldn't you?

Jul 29 '05 #35

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
10426
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
10207
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
10154
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
9029
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
7537
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
6776
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
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
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
3713
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.