473,396 Members | 1,871 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.

How to add parameters to a function passed as a paramter?

Here's an interesting problem...

I have 2 functions, aFunc() and bFunc(). I call aFunc() passing a call
to bFunc() as a parameter. Function aFunc() executes bFunc(). Function
bFunc() lists the parameter values passed to it.

OK, here's the twist...

I want to add some parameters to bFunc() from inside aFunc(). Can that
be done?

Sorry no prizes, except the satisfaction of the solution :)

Regards,
Steve
aFunc(function() { bFunc(); } );

function aFunc(f) {
var x = 1;
var y = 2;

// add x, y as parameters to function f()
// ???

// execute the parameter function
f();
}

function bFunc() {
for (var i = 0; i < arguments.length; ++i) {
alert(arguments[i]);
}
}
Jul 23 '05 #1
4 5194
On 26 Oct 2004 14:21:29 -0700, Steve Neill <sn****@mxlogic.com> wrote:
I have 2 functions, aFunc() and bFunc(). I call aFunc() passing a call
to bFunc() as a parameter. Function aFunc() executes bFunc(). Function
bFunc() lists the parameter values passed to it.

OK, here's the twist...

I want to add some parameters to bFunc() from inside aFunc(). Can that
be done?


Yes, but your call to aFunc needs to be changed.

Functions are objects, and just like all other objects, you can refer to
them with any number of identifiers. Consider:

function myFunction() {
}

var yourFunction = myFunction;

You can now invoke myFunction with either myFunction() or yourFunction()
with exactly the same results. For your particular case, this would become:

function aFunc(f) {
var x = 1,
y = 2;

f(x, y); // Call bFunc with arguments x and y.
}

function bFunc() {
for(var i = 0, n = arguments.length; i < n; ++i) {
alert(arguments[i]);
}
}

aFunc(bFunc); // Note: no parentheses on bFunc!

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
sn****@mxlogic.com (Steve Neill) wrote in message news:<25**************************@posting.google. com>...
Here's an interesting problem...

<snip />

Am I missing something?

aFunc(bFunc);

function aFunc(f) {
var x = 1;
var y = 2;

// add x, y as parameters to function f()
// ???

// execute the parameter function
f(x,y);
}

function bFunc() {
for (var i = 0; i < bFunc.arguments.length; ++i) {
alert(bFunc.arguments[i]);
}
}
Jul 23 '05 #3
On 27 Oct 2004 06:12:14 -0700, Bob Gregory <bo********@ppsltd.net> wrote:

[snip]
Am I missing something?
Not especially, but...

[snip]
function bFunc() {
for (var i = 0; i < bFunc.arguments.length; ++i) {
alert(bFunc.arguments[i]);
}
}


....the arguments object is not a property of the function, but of the
function's activation object. Effectively, it is a local variable to
accessed like all other local variables.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Thank you Michael. I didn't realize I could pass a function that way
(now I do!) This solves the problem -- Thank you
Jul 23 '05 #5

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

Similar topics

1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
1
by: Julia | last post by:
Hi, I have been asked this before but I think that I didn't explain myself well I am using exception and logging and I would like to log the parameters which was passed to the function...
5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
3
by: Pieter | last post by:
Hi, I have a View which contains (of course) several columns. Now I want to make a Stored Procedure that does a Select based on the parameters. For exemple: One time I want to select all the...
1
by: jacobyv | last post by:
hi i created survey.asp which displays the survey passed through the name paramter in the url. it works fine if i open the page like this. http://url/survey.asp?name=survey1 but now i would...
0
by: Dawn | last post by:
Hi, I'm pretty new to WebServices and I'm a tester not a developer. The WebService that I have been asked to test requires parameters that are both input and ouput parameters. In addition to...
3
by: danbraund | last post by:
Hi everyone, I'm a long time C coder, who is coding his final year project in C++ to run under the MIT click routing system. Being fairly new to the OO side of the language, my problem is this: ...
1
by: Giojo | last post by:
Hi to all! I have a logging class, which is used to log errors automatically. With StackFrame.GetMethod().GetParameters() function, I am able to read all parameter information except the real...
4
by: wyleu | last post by:
I'm trying to supply parameters to a function that is called at a later time as in the code below: llist = for item in range(5): llist.append(lambda: func(item)) def func(item): print...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
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
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,...
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...

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.