By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

I need assistance using callback

P: n/a

Hi All
please help me using callback .
my expected results are , alert ('1,2,3)
but the results are alert(undefine)

can anyone expain me why? thanks
function ActivateFuncOnObjects(list,Callbackfunction)
{
return function() { Callbackfunction.apply(list); };
}

function AlertF(text)
{
alert(text);
}

==============================================
var fn = ActivateFuncOnObjects2('1,2,3',AlertF);
fn();
Oct 23 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Montezuma's Daughter meinte:
Hi All
please help me using callback .
my expected results are , alert ('1,2,3)
but the results are alert(undefine)

can anyone expain me why? thanks
function ActivateFuncOnObjects(list,Callbackfunction)
{
return function() { Callbackfunction.apply(list); };
}
Apply expects a reference to "this" as the first parameter [1].
Callbackfunction.apply(null, list) should work.
Gregor

[1]
<https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/apply>
Oct 23 '08 #2

P: n/a
On 2008-10-23 14:26, Montezuma's Daughter wrote:
my expected results are , alert ('1,2,3)
but the results are alert(undefine)
function ActivateFuncOnObjects(list,Callbackfunction)
{
return function() { Callbackfunction.apply(list); };
You don't need apply() here, just write Callbackfunction(list). If this
is a reduced example, and you do need to use apply() for some reason,
you'll have to call it with the correct arguments. The first argument is
an object to be used as 'this' in Callbackfunction, and the second
argument is an array.

https://developer.mozilla.org/en/Cor...Function/apply
- Conrad
Oct 23 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.