|
|
|
|
|
by natedub
5222 days ago
|
|
Ian Bicking gave a talk on the similarities and differences between Python and Javascript that might be helpful, but it's pretty high level:
http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-jav... The key similarities in my mind are: 1) In both python and javascript, the class and prototype are exposed and can be called explicitly if desired: MyClass.method(my_instance, arg1, arg2)
MyClass.prototype.method.call(my_instance, arg1, arg2);
2) Python will automatically bind methods when you retrive them from an instance. Unless you explicitly bind a function in JS, the "this" parameter is specified at call time: whatever comes before the dot is used as "this". Ultimately they're both first class objects and the difference to the developer is notation: bound_method = my_instance.method
bound_method = my_instance.method.bind(my_instance);
3) Attribute lookups in Python behave very similarly to property lookups in Javascript. Python has a modified resolution order for searching for an attribute through its list of parent classes. Javascript will look for an attribute in a series of prototypes (since in JS, an instance's prototype is just an object, so it too can have a prototype). Python is superior here because it supports multiple inheritance, but overall the resolution behaviour is essentially the same.Can anyone think of any other common ground? |
|