Mercurial > hg > config
diff python/aspects.py @ 124:2f0baf81372f
added illustration of doing aspects in python
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 08 Feb 2011 10:08:44 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/aspects.py Tue Feb 08 10:08:44 2011 -0800 @@ -0,0 +1,18 @@ +class MakePythonLikeJavascript(object): + def __getattr__(self, name): + return undefined + +class undefined(MakePythonLikeJavascript): + def __nonzero__(self): + return False + def __str__(self): + return 'undefined' + __repr__ = __str__ +undefined = undefined() # singleton + +if __name__ == '__main__': + foo = MakePythonLikeJavascript() + foo.bar = 5 + print foo.bar + print foo.fleem + print foo.fleem.flarg