如何使用 Function() 构造器定义 JavaScript 函数?
Function() 构造器期望任何数量的字符串参数。最后一个参数是函数的主体——它可以包含任意 JavaScript 语句,彼此用分号分隔。
示例
你可以尝试运行以下代码使用 new Function 构造器调用函数 −
<html>
<head>
<script>
var func = new Function("x", "y", "return x*y;");
function multiplyFunction(){
var result;
result = func(15,35);
document.write ( result );
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type = "button" onclick = "multiplyFunction()" value = "Call Function">
</form>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP