changeset 13:7f8a793ba4ae

Added section on operator overloading, special methods, and properties.
author Atul Varma <varmaa@toolness.com>
date Thu, 05 Jun 2008 19:54:36 -0700
parents 506880d3a791
children 33f8f445378d
files PythonForJsProgrammers.txt
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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.