1. 程式人生 > >ECMAScript5/6新特性之函式的優化

ECMAScript5/6新特性之函式的優化

/*函式的優化*/
//以前
function sum(a,b) {
    return a+b;
}
//優化
const add = (a,b)=>a+b;

//以前
const p1 = {
    name:"mike",
    age:21,
    sayHello:function(){
        console.log("hello");
    }
}
//優化
const p2 = {
    name:"mike",
    age:21,
    sayHello(){
        console.log("hello");
    }
}

//以前
const hello = function(person){
    console.log(person.name,person.age);
}
//優化
const hello2 = function({name,age}){
    console.log(name,age);
}
//再度優化
 const hello3 = ({name,age})=>{
    console.log(name,age);
}