zoukankan      html  css  js  c++  java
  • 06 扩展的对象的功能

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <script>
            //es6直接写入变量和函数,作为对象的属性和方法
            // const name = 'walter',age = 20;
            // const person = {
            //     name,
            //     age,
            //     sayName(){
            //         console.log(this.name)
            //     }
            // }
            // person.sayName()
            //
            // function fn(x,y) {
            //     return {x,y}
            // }
            // console.log(fn(10,20))//x: 10 y: 20



            //直接写入变量和函数,设置和获取选择器
            // let cart = {
            //     wheel:4,
            //     set(newVal){
            //         if (newVal < this.wheel){
            //             throw new Error('轮子数太少了')
            //         }
            //         this.wheel = newVal;
            //     },
            //     get(){
            //         return this.wheel;
            //     }
            // }
            // cart.set(6)

            const obj = {};
            obj.isShow = true;
            const name = 'a';
            obj[name+'bc'] = 123;
            console.log(obj);



            //对象的方法
            //is() === 比较两个值是否严格相等
            console.log(Object.is(NaN,NaN))//true

            //assign() 对象的合并  Object.assign(新对象,被合并对象1,被合并对象2)
            let newObj = Object.assign({},{a:1},{b:2})
            console.log(newObj)//{a: 1, b: 2}

        </script>
    </body>
    </html>
  • 相关阅读:
    Tornado入门2
    Tornado框架入门
    Nginx下载及安装
    串口通信工程笔记一
    串口通信工程笔记之协议设计
    串口通信之并发与单步
    串口通信属性及事件解析
    串口通信之超时
    VC程序Debug版本和Release版本运行不一致问题
    串口通信之DataReceive事件触发时机
  • 原文地址:https://www.cnblogs.com/wuhui1222/p/14202533.html
Copyright © 2011-2022 走看看