|
|
|
|
|
by reipahb
4054 days ago
|
|
Actually, what you get when referencing x.test in Python is a bound method: >>> foo.test
<unbound method foo.test>
>>> x.test
<bound method foo.test of <__main__.foo instance at 0xf74d68ac>>
>>> z = x.test
>>> z(123)
<__main__.foo instance at 0xf74d68ac> 123
I really like this behavior in Python. Unfortunately, JavaScript does not behave the same way, as you see in the last couple of lines in your example. You can however get the same result by manually binding the method to the object: z = x.test.bind(x)
// z is: function () { [native code] }
z(123)
// foo {test: function} 123
|
|