Skip to content

Instantly share code, notes, and snippets.

@KKrisu
Created May 12, 2016 19:52
Show Gist options
  • Save KKrisu/9fc27b1c709e34a2d52f287cf473aaea to your computer and use it in GitHub Desktop.
Save KKrisu/9fc27b1c709e34a2d52f287cf473aaea to your computer and use it in GitHub Desktop.
Object literal ES6
parent.console.clear();
// var {a, b} = {a: 1, b: 2};
var a = 1;
var b = 2;
// console.log(a, b);
var bar = 'test';
var o = {
// a: a,
// b: b,
a, b,
['b' + 2]: 4,
[bar]: 8,
f1: function() {},
f2() {},
// get foo() {...},
// set foo(value) {...},
};
o['a' + 1] = 3;
Object.defineProperty(o, 'foo', {
get: () => {
return 3;
},
set: (value) => {
console.log('set to', value);
}
});
console.log(o.foo);
o.foo = 5;
console.log(o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment