Created
October 11, 2017 14:09
-
-
Save prof3ssorSt3v3/83e87325cb9775cd9a5030c2f244abf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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