Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Last active December 11, 2015 06:12
Show Gist options
  • Save aaronfrost/cc9bedf98e92b1612a2d to your computer and use it in GitHub Desktop.
Save aaronfrost/cc9bedf98e92b1612a2d to your computer and use it in GitHub Desktop.
Show a defined property
var foo = {};
Object.defineProperty(a, "bar",{
get: getFoo,
set: setFoo
});
export default foo;
function getFoo(){
//do shiz
}
function setFoo(val){
//do shiz
}
import foo from "foo";
console.log(foo.bar); //calls the get defined property
foo.bar = 1; //calls the set defined property
console.log(foo.bar); //calls the get defined property
//WHY DO I LIKE THE ABOVE MORE THAN THE FOLLOWING
console.log(foo.bar()) //or foo.getBar()
foo.bar(1) //or foo.setBar(1)
console.log(foo.bar()) //or foo.getBar()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment