intermediate javascript: assign a function with its parameter to a variable and execute later

来源:互联网 发布:linux lpctstr 编辑:程序博客网 时间:2024/06/05 04:48

http://stackoverflow.com/a/7776322

I have a function in javascript:

function alertMe($a){   alert($a);}

Which I can execute like this: alertMe("Hello");

I want to do is assign alertMe("Hello") with the "Hello" parameter to a variable $func,and be able to execute this later by doing something like $func();


I would like to add the comment as answer

Code

//define the functionfunction alertMe(a) {    //return the wrapped function    return function () {        alert(a);    }}//declare the variablevar z = alertMe("Hello");//invoke nowz();


0 0