Skip to content

Instantly share code, notes, and snippets.

@Bluebie
Forked from ELLIOTTCABLE/gist:173621
Created August 24, 2009 02:54
Show Gist options
  • Save Bluebie/173622 to your computer and use it in GitHub Desktop.
Save Bluebie/173622 to your computer and use it in GitHub Desktop.
// In this example, the private_thing is more like a private class variable than a private instance variable.
var F=function(){
var private_thing = '';
this['private_thing'] = function(){ return private_thing; }; // get…
this['set_private_thing'] = function(o){ private_thing = o; }; // set…
this['public_thing'] = '';
};
thingie_one = new F();
thingie_two = new F();
thingie_one['public_thing'] = 'dog';
thingie_two['public_thing'] = 'cat';
thingie_one.set_private_thing('house');
thingie_two.set_private_thing('car');
puts(thingie_one['public_thing']);
puts(thingie_two['public_thing']);
puts(thingie_one.private_thing());
puts(thingie_two.private_thing());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment