Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created October 11, 2017 14:09
Show Gist options
  • Save prof3ssorSt3v3/83e87325cb9775cd9a5030c2f244abf4 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/83e87325cb9775cd9a5030c2f244abf4 to your computer and use it in GitHub Desktop.
// es6-object-methods.js
// New ways of declaring methods for objects
// getters and setters for object properties
var log = console.log;
let x = 7;
let obj = {
_prop1: 1979,
get prop1(){
return this._prop1;
},
set prop1(_val){
this._prop1 = _val;
},
prop2: 'Alien',
x,
prop3(){
log('called prop3');
}
};
obj.prop3();
log(obj.x);
log( obj.prop1 );
obj.prop1 = 1980;
log( obj.prop1 );
/*var obj = {
prop1: 1979,
prop2: 'Alien',
prop3: function(){
}
};*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment