Link to home
Start Free TrialLog in
Avatar of BeerFizz
BeerFizz

asked on

Javascript with callback


Hi

I have a simple piece of example code, in which I am passing a function (for call back) into a class.
When this function is called back, I wish to have a parameter passed back but this is not working.

Thanks for you help
Phil
<?php
  
?>

<!DOCTYPE html>
<head>

<script language='javascript' type='text/javascript'>
window.onload=init;

function init() {
    var y;
    var myClassObj = new MyClass(5, calledBack); 
}

function calledBack(x) {
    alert("Got called back with "+x);
}

    
function MyClass(val, f)
{
    var data = val;
    
    function someFunc(x) 
    {
       alert("someFunc "+x);
       f.call(x);
    }
    
    someFunc(data);
}
</script>


</head>
<body>

<div style="" >

</div>

</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jasonduan
jasonduan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BeerFizz
BeerFizz

ASKER

Perfect!  Thank you.