I need assistance using callback

  • Thread starter Montezuma's Daughter
  • Start date
M

Montezuma's Daughter

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();
 
G

Gregor Kofler

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top