Skip to content

Instantly share code, notes, and snippets.

@netpoetica
Created August 31, 2012 19:00
Show Gist options
  • Save netpoetica/3557429 to your computer and use it in GitHub Desktop.
Save netpoetica/3557429 to your computer and use it in GitHub Desktop.
Properties (Getter and Setter accessible attributes) in JavaScript. An attempt to make variables with getters and settes in JavaScript easily. Basically, make them an object instead. Maybe useful to someone!
​var Property = function(vari){
console.log("Creating a public accessor...");
this.vari = vari;
return function(){
if(arguments.length > 0){
console.log("Setting the variable to " + arguments[0] + "...");
vari = arguments[0];
return;
}
console.log("Getting the variable...");
return vari;
};
};
var a = new Property("ssst");
​console.log(a());
a("keith");
console.log(a());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment