Created
June 19, 2013 14:47
-
-
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…
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
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