zoukankan      html  css  js  c++  java
  • es6 对象的扩展

    var foo = 'aaaa';
    var baz = {foo};  //{foo: 'aaaa'}
    foo = 'bbbb';
    baz;  //{foo: 'bbbb'}
    function f(x, y){
      return {x, y}
    }

    function f(x, y) {
      return { x: x, y: y };
    }

     
    var o ={
      f(){
        alert(1)
      }
    }

    var o = {
      f: function f() {
        alert(1);
      }
    };

    var borth = '1987-02-02'
    var Person = {
      name: 'zhangsan',
      borth,
      hello(){
        console.log('my name is ' + this.name)
      }
    }
    
    ==
    
    var borth = '1987-02-02';
    var Person = {
      name: 'zhangsan',
      borth: borth,
      hello: function hello() {
        console.log('my name is ' + this.name);
      }
    };

     模块模式

    var ms = {}
    
    function getItem(key){
      return key in ms? ms[key]: null;
    }
    
    function setItem(key, value){
      ms[key] = value;
    }
    
    function clear(){
      ms = {}
    }
    
    module.export = {getItem, setItem, clear}
    ==
    module.export = {
        getItem: getItem,
        setItem: setItem,
        clear: clear
    }
    var cart = {
      _wheels: 4,
      get wheels(){
        console.log('get')
        return this._wheels;
      },
      set wheels(value){
        console.log('set');
        this._wheels = value;
      }
    }
    var obj = {
      class(){}
    }
    ==
    var obj = {
      class: function _class() {}
    };
    var obj = {
      *m(){
        yield 'hello'
      }
    }
    ==
    var obj = {
      m: regeneratorRuntime.mark(function m() {
        return regeneratorRuntime.wrap(function m$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return 'hello';
    
              case 2:
              case 'end':
                return _context.stop();
            }
          }
        }, m, this);
      })
    };
  • 相关阅读:
    GET请求和POST请求的本质区别
    go切片的Add与Del
    滚动到指定位置的问题
    promise---批量调用接口,等待所有的请求发完
    this argument
    html2canvas截图 下载图片
    数组合并去重
    vue项目踩坑
    关于java中的栈和堆
    用python实现一个最简单版本的mysql数据库连接池
  • 原文地址:https://www.cnblogs.com/xudy/p/6804755.html
Copyright © 2011-2022 走看看