Javascript with callback

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


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

<!DOCTYPE html>

<script language='javascript' type='text/javascript'>

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


<div style="" >



Open in new window

Question by:BeerFizz
LVL 11

Accepted Solution

jasonduan earned 500 total points
ID: 35012289
change your code line #28 from;

Author Closing Comment

ID: 35012321
Perfect!  Thank you.

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now