js 使用方法名作参数

来源:互联网 发布:充话费软件下载 编辑:程序博客网 时间:2024/04/29 00:52

js里 可以把方法名作为参数传递, 这样可以在一个统一的方法中调用不同的函数,如下

<html><head><script type="text/javascript">function realFunc() {alert("this is the real function");}function callMary() {alert("this is Mary Speaking");}function callme() {var someFunc = realFunc;someFunc();}function callsomeone(whatFunc) {whatFunc();}</script></head><body><div><input type="button" value="callme" onclick="callme()"> </input><input type="button" value="callsomeone" onclick="callsomeone(realFunc)"> </input><input type="button" value="callsomeone" onclick="callsomeone(callMary)"> </input></div></body></html>
原创粉丝点击