473,396 Members | 1,758 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,396 software developers and data experts.

Functions passed as arguments

I have a function source() to show the definitions of functions passed to it

function sourceAsHTML() {
var s=''
for (var i=0; i<arguments.length; i++) {
alert(arguments[i])
s +=
'<PRE>'
+ arguments[i].toString().replace (/</g, '&lt;')
+ '</PRE>'
}
return s
}

and it works nicely, except in the case of a class prototype assigned to an
anonymous function
i.e.

function myClass () {}
function myClass.prototype.foobar = function () { /* foobar */ }

alert (sourceAsHTML(myClass.prototype.foobar))

.....
the alert shows
<PRE>function () { /* foobar */ }</PRE>
which is close, but it doesn't show that it 'belongs' to
myClass.prototype.foobar.
So the question is, when passed a function as an arg is there a way to know
the function name or context (i.e. prototype) ?
--
Richard A. DeVenezia
Jul 20 '05 #1
2 1662
"Richard A. DeVenezia" <ra******@ix.netcom.com> writes:
I have a function source() to show the definitions of functions passed to it ....
+ arguments[i].toString().replace (/</g, '&lt;')
You might also want to replace "&" by "&amp;".

and it works nicely, except in the case of a class prototype assigned to an
anonymous function
i.e.

function myClass () {} function myClass.prototype.foobar = function () { /* foobar */ }
The first "function" is wrong.
What you have is an anonymous function. You then assign it to some
arbitrary object property. The function itself couldn't care less,
so there is no way to get that information from the function object
alone.
alert (sourceAsHTML(myClass.prototype.foobar))
....
the alert shows
<PRE>function () { /* foobar */ }</PRE>
which is close, but it doesn't show that it 'belongs' to
myClass.prototype.foobar.
You have to tell it. The function doesn't know.
So the question is, when passed a function as an arg is there a way to know
the function name or context (i.e. prototype) ?


The function you created doesn't have a name. It can have more than one
context, but the function don't have to know until it is called.

So, no.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
>
So the question is, when passed a function as an arg is there a way to know the function name or context (i.e. prototype) ?


The function you created doesn't have a name. It can have more than one
context, but the function don't have to know until it is called.

So, no.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'


Lasse:

Thanks, I thought as much, but wanted to be sure.
So for anonymous functions I pass the function name as a string.
In my loop if the arg is a string the 'source' I make HTMLy is the arg
window[arg]

Richard
Jul 20 '05 #3

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

Similar topics

3
by: lwoods | last post by:
Program (PHP5): <?php $a='x'; $b=5; foo($a,$b); echo "a=$a b=$b"; function foo($x,$y){
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
0
by: madstyle51 | last post by:
I just wrote a program with all the source code to find the max, min, range, and standard deviation of a bunch of numbers in an array... Now I have to rewrite the program using prototype commands and...
13
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member...
11
by: sameer.oak | last post by:
I am looking for some comprehensive tutorials on how to write call back functions in C. Can anyone help me? - sameer oak.
2
by: PatrickMinnesota | last post by:
I've been reading the docs and looking for an answer and seem stuck. I'm either not looking in the right places or not understanding what I'm reading. I have a bunch of functions. I want to put...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.