Created
July 4, 2015 20:42
-
-
Save mr-karan/11f68be650bafef3aa71 to your computer and use it in GitHub Desktop.
js snippets
This file contains 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
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Defining_getters_and_setters | |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get | |
var log = ['test']; | |
var obj = { | |
get latest () { | |
if (log.length == 0) return undefined; | |
return log[log.length - 1] | |
} | |
} | |
console.log (obj.latest); // Will return "test". | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment