Fork me on GitHub
魔芋铃

【01】用构造器创建函数中的小知识

【01】用构造器创建函数中的小知识
 
 
魔芋:在看ES5.1标准文档时。
Function (p1, p2, … , pn, body)
 

NOTE It is permissible but not necessary to have one argument for each formal parameter to be specified. For example, all three of the following expressions produce the same result:

(为每个形参指定一个参数是允许的,但没必要。例如以下三个表达式产生相同的结果:)

new Function("a", "b", "c", "return a+b+c") 

new Function("a, b, c", "return a+b+c") 

new Function("a,b", "c", "return a+b+c")

 
魔芋:例子:
var funa = new Function("a", "b", "c", "return a+b+c");
var funb = new Function("a, b, c", "return a+b+c");
var func = new Function("a,b", "c", "return a+b+c");

console.log(funa(1, 2, 3), funb(1, 2, 3), func(1, 2, 3));
 
var a= "moyu";
var funa = new Function(a, "b", "c", "return a+b+c");
/* function funa(moyu,b,c){

	return a+b+c;
}
*/
var funb = new Function("a, b, c", "return a+b+c");
var func = new Function("a,b", "c", "return a+b+c");

console.log(funa(1, 2, 3), funb(1, 2, 3), func(1, 2, 3));
 
 

**

posted @ 2018-03-08 13:35  魔芋铃  阅读(149)  评论(0编辑  收藏  举报