Home > Web Front-end > JS Tutorial > body text

Example of es6 syntax object extension

一个新手
Release: 2017-10-12 09:31:26
Original
1289 people have browsed it

{    //简洁表示法
    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:'a',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'//     }// }
Copy after login

The above is the detailed content of Example of es6 syntax object extension. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template