?
Solved

Javascript with callback

Posted on 2011-03-01
2
Medium Priority
?
279 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 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