/ Published in: JavaScript
This example can be extended to include a more general object. here I get or set a single value
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var value = false; function gettersetter(bool){ // _args = array with function arguments var _args = Array.prototype.slice.call(arguments); if(_args.length == 0){ // if no arguments -> define get method return value; } else if(_args.length > 0){ value = bool; } } How to use it: // getter var newValue = gettersetter(); // setter gettersetter(true);