Skip to content

Instantly share code, notes, and snippets.

@zhjuncai
Created June 19, 2013 14:47
Show Gist options
  • Save zhjuncai/5814895 to your computer and use it in GitHub Desktop.
Save zhjuncai/5814895 to your computer and use it in GitHub Desktop.
JavaScript getter setter Starting in JavaScript 1.8.5, the get operator: can have an identifier which is either a number or a string; must have exactly zero parameters (see Incompatible ES5 change: literal getter and setter functions must now have exactly zero or one arguments for more information); must not appear in an object literal with anot…
var entry = {
log : [],
set current : function(str){
return this.log[this.log.length-1] = str;
}
get latest : function(){
if(this.log.length > 0){
return this.log[this.length - 1];
}else{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment