原始方式声明函数
function say(name){ console.log("hello" + name); }
箭头函数
var say = name => console.log("hello " + name); say("zhanshen");
多个参数的话
function sum1(a, b) { return a + b; } var sum2 = (a, b) => a + b; console.log(sum1(2, 3)); console.log(sum2(2, 3));
复杂函数声明
var MAX = (a, b) => { if (a > b) { return a; } else { return b; } }
箭头函数+解构表达式
person = { name: 'zhanshen', age: 12, language: ['java', 'python', 'go'] } var hello = (person) => { console.log("hello "+person.name); } // 用结构表达式 var hi = ({name}) => { console.log("hi " + name); } hello(person) hi(person)