# HG changeset patch # User Atul Varma # Date 1212720876 25200 # Node ID 7f8a793ba4aee5886baf7993310d7f5f6c1e33fb # Parent 506880d3a791d7aa703cbc2332abbbeac6fae5c1 Added section on operator overloading, special methods, and properties. diff -r 506880d3a791 -r 7f8a793ba4ae PythonForJsProgrammers.txt --- a/PythonForJsProgrammers.txt Thu Jun 05 19:38:36 2008 -0700 +++ b/PythonForJsProgrammers.txt Thu Jun 05 19:54:36 2008 -0700 @@ -454,8 +454,10 @@ really prototype-based, it's not easy to dynamically add or remove methods to existing objects on-the-fly. -An object's methods are also bound to the object itself, so--unlike in -Javascript--if they're "disconnected" from the object, they still work: +An object's methods are also bound to the object itself once it's +created; that is, the ``self`` parameter that's passed to them is +always the same, unlike the ``this`` parameter in JavaScript which +changes based on the object the function is attached to: >>> f = Foo(5) Foo created. @@ -463,6 +465,17 @@ >>> doThing() 6 +Operator Overloading, Special Methods, and Properties +===================================================== + +Classes can define methods with special names to do all sorts of +dynamic things, from operator overloading to custom properties and +more. Some of these dynamic features are available in JavaScript, and +some aren't. You can read about tehm more in the Python Reference +Manual's section on `special method names`_. + +.. _`special method names`: http://docs.python.org/ref/specialnames.html + Exceptions ========== @@ -498,7 +511,3 @@ TODO: Mention generators, generator comprehensions/expressions, array comprehensions, other stuff lifted from Python by JS. - -TODO: Mention 'special' methods like __getattr__, etc. - -TODO: Explain method binding better.