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);
}

猜你喜欢

转载自blog.csdn.net/shijiaolong0/article/details/85322946