1.函数构造器
new Function(……)
不常用
var add = new Function("first", "second", "return first + second");
console.log(add(1, 1)); // 2
2.函数声明式
function doSomething() { }
常用
function doSomething() {
console.log('this is doSomething.');
}
doSomething();
3.匿名函数表达式
var doAnotherThing = function() { }
常用
var doAnotherThing = function() {
console.log('this is doAnotherThing.');
};
doAnotherThing();
网友评论