News for hackers. Stuff that matters.
Re:Replacing ‘that = this’ assignments in JavaScript with Ar... by orf on Friday April 14, 2017 @06:28PM (#14117912)
I wouldn't say the Python solution is more complicated (complex, maybe), it's quite elegant and it essentially boils down to just pre-setting the first argument to the class instance or class value.

You can do it yourself:

   >> def x(*args): print(args)
   
   >> new_func = a.__get__('silly sausage')

   >> new_func()

   ('silly sausage',)
When you do instance.method() Python will look up 'method' inside 'instance'. If 'method' is a descriptor (with functions are), then `__get__` is called and the first argument is set to 'instance'

Here are the docs if anyone is interested: https://docs.python.org/3/howto/descriptor.html

Re:Replacing ‘that = this’ assignments in JavaScript with Ar... by int_19h on Friday April 14, 2017 @08:37PM (#14118613)
Yeah, I meant descriptors themselves. Conceptually, having an ability in the language for an object to do some special handling when it's retrieved as a member of another object is a very powerful tool, and once you have it, it solves this particular problem neatly. But it's also an unusual thing to have, and few people are aware that something like this is at play every time you write something like `a.b`.