Last active
December 11, 2015 06:12
-
-
Save aaronfrost/cc9bedf98e92b1612a2d to your computer and use it in GitHub Desktop.
Show a defined property
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
var foo = {}; | |
Object.defineProperty(a, "bar",{ | |
get: getFoo, | |
set: setFoo | |
}); | |
export default foo; | |
function getFoo(){ | |
//do shiz | |
} | |
function setFoo(val){ | |
//do shiz | |
} |
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
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