js中声明函数及调用

2017-1-31 liyangweb.com 李杨 JavaScript

方式一(最常见的方式):

function fun1(param1, param2) {
    console.log(param1);
    console.log(param2);
}
fun1(111,222);

方式二(匿名函数方式):

var fun2 = function (param1, param2) {
    console.log(param1);
    console.log(param2);
}
fun2(111,222);

方式三(对象方式):

var fun3 = new Function ("param1", "param2", "console.log(param1, param2)");
fun3(111,222);

方式四(胖箭头方式):

//没有参数时,括号中留空,但不可省略括号,函数体只有一行时,可以省略大括号
var fun4 = ()=>console.log("This is fun4!");
fun4();

var fun5 = param1 => {
    console.log("This is " + param1)
}
fun5(555);

var fun6 =  (param1, param2) => {
    console.log(param1, param2)
}
fun6(666,777);

标签: JavaScript js

发表评论:

Powered by emlog 冀ICP备13011830号-1