es6 语法 (对象扩展)

{
    //简洁表示法
    let o = 1;
    let k = 2;
    let es5 = {
        o:o,
        k:k
    };
    let es6 = {
        o,k
    };
    console.log(es5,es6); //1,2;1,2

    let es5_method = {
        hello:function(){
            console.log('hello'); //hello
        }
    };
    let es6_method = {
        hello(){
            console.log('hello'); //hello
        }
    };
    console.log(es5_method.hello(),es6_method.hello()); //undefined undefined
}
{
    //属性表达式
    let a = 'b';
    let es5_obj = {
        a:'c',
        b:'c'
    };
    let es6_obj = {
        [a]:'c'
    };
    console.log(es5_obj,es6_obj) //{a:'c',b:'c'};{b:'c'};
}

{
    //新增api
    console.log('字符串',Object.is('abc','abc'),'abc'==='abc'); //true true
    console.log('数组',Object.is([],[]),[]===[]); //false false
    console.log('拷贝',Object.assign({a:'a'},{b:'b'}));//{a: "a", b: "b"}
    let test = {k:123,o:456};
    for(let [key,value] of Object.entries(test)){
        console.log(key,value); // k 123,o 456
    }
}

// {
//     //扩展运算符(支持不友好)
//     let {a,b,...c} = {a:'test',b:'kill',c:'ddd',d:'ccc'};
//     c = {
//         c:'ddd',
//         d:'ccc'
//     }
// }

 

posted @ 2017-10-10 22:36  abcByme  阅读(889)  评论(0编辑  收藏  举报