Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript callback on function [closed]

I'm trying run a function in return of another function:

var my_func = function(func){
	if(typeof func=="function") return func;
}
my_func(function(){
	alert('hello world!');
});

but it does not work!

like image 664
Nabi Avatar asked May 16 '26 05:05

Nabi


1 Answers

You need to call the function

var my_func = function (func) {
    if (typeof func == "function") return func();
    //                                        ^^ call function
}
my_func(function () {
    alert('hello world!');
});
like image 192
Nina Scholz Avatar answered May 18 '26 18:05

Nina Scholz