Skip to content

Instantly share code, notes, and snippets.

@mr-karan
Created July 4, 2015 20:42
Show Gist options
  • Save mr-karan/11f68be650bafef3aa71 to your computer and use it in GitHub Desktop.
Save mr-karan/11f68be650bafef3aa71 to your computer and use it in GitHub Desktop.
js snippets
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