Created
August 31, 2012 19:00
-
-
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!
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 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