Solved

Javascript with callback

Posted on 2011-03-01
2
278 Views
Last Modified: 2012-05-11

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

0
Comment
Question by:BeerFizz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
jasonduan earned 500 total points
ID: 35012289
change your code line #28 from
f.call(x);
to
f(x);
0
 

Author Closing Comment

by:BeerFizz
ID: 35012321
Perfect!  Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to dynamically set the form action using jQuery.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question