Question: I have a little problem with creating a new function from a string.
The example: I have a div, and some buttons. One of the buttons just make my div animating, nothing else. But the other button make the div animating and after the animation is complete, call a new function.

I have to handle the new, following function as a variable, because there will be a lot of function I have to call after the div animated.

Here is an example I made: <http://jsfiddle.net/AmVSq/3/>. I hope you can understand my problem.

I found the `new Function();` in JavaScript but it just left me in doubt and the JS console did not log anything.

Can somebody tell me what am I doing wrong?
Thank you so much..

Answer: 
What you're doing wrong is using `new Function` at all. The correct way is to just pass the function, which are objects like anything else in JavaScript:

<http://jsfiddle.net/minitech/AmVSq/6/>

```
<div><a href="javascript:void(0)" onclick="close_div();">Close Div</a></div>
<div><a href="javascript:void(0)" onclick="close_div(alert_me);">Close Div then do something</a></div>
<div><a href="javascript:void(0)" onclick="close_div(confirm_me);">Close Div then do another thing</a></div>
<div id="wrap"></div>​

```

```
function close_div( next_function ) {
    $('#wrap').animate({ 'height': '-=100px' }, 300, function() {
        if(next_function) {
            next_function();
        }
    });
}

function alert_me() {
    alert( 'The animation is complete' );
}

function confirm_me() {
    confirm('Are you sure?');
}

```

Or, more concisely, `$('#wrap').animate({height: '-100px'}, 300, next_function);`.
You don't need to make the function into a string, you can pass functions as arguments to other functions in Javascript.

For example:

```
function get_message1() {
    return "hello world";
}

function get_message2() {
    return "yay for first-class functions";
}

function print_message(message_func) {
    console.log(message_func())
}

print_message(get_message1);
print_message(get_message2);

```