-
-
Save Bluebie/173622 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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