Created
April 18, 2013 15:03
-
-
Save johnsmith17th/5413436 to your computer and use it in GitHub Desktop.
Defining Getters and Setters in NodeJS
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 sys = require('sys') | |
function Person(age){ | |
this.__defineGetter__('age', function(){ | |
return age | |
}) | |
this.__defineSetter__('age', function(arg){ | |
age = arg | |
}) | |
} | |
var dude = new Person(18) | |
sys.puts(dude.age) | |
dude.age = 32 | |
sys.puts(dude.age) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment