Created
January 23, 2014 14:31
-
-
Save nakamuray/8579365 to your computer and use it in GitHub Desktop.
python で closure 使って class みたいなの作る
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
def ClosureObject(x): | |
self = dict() | |
self['x'] = x | |
def getX(): | |
return self['x'] | |
self['getX'] = getX | |
def setX(x): | |
self['x'] = x | |
self['setX'] = setX | |
return self | |
obj = ClosureObject(10) | |
assert obj['getX']() == 10 | |
obj['setX'](20) | |
assert obj['getX']() == 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment