码迷,mamicode.com
首页 > 其他好文 > 详细

es6 对象的扩展

时间:2017-05-04 01:37:58      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:style   alert   hang   bbb   div   hello   ons   module   set   

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

 

es6 对象的扩展

标签:style   alert   hang   bbb   div   hello   ons   module   set   

原文地址:http://www.cnblogs.com/xudy/p/6804755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!