Skip to content

Instantly share code, notes, and snippets.

@johnsmith17th
Created April 18, 2013 15:03
Show Gist options
  • Save johnsmith17th/5413436 to your computer and use it in GitHub Desktop.
Save johnsmith17th/5413436 to your computer and use it in GitHub Desktop.
Defining Getters and Setters in NodeJS
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