News for hackers. Stuff that matters.
Re:Javascript Fundamentals: ‘this’ keyword by wruza on Sunday August 26, 2018 @02:53AM (#17844655)
Yeah, one most complex way to do it. I just tested my assertion for the sake of truth and it seems correct:

  class Foo:
      def bar(self, x):
          print 'bar', x
  
  def f(x): print 'f', x
  
  foo = Foo()
  foo.baz = f

  print(foo.bar)  # <bound method Foo.bar of <__main__.Foo object>>
  print(foo.baz)  # <function f>
  foo.bar(5)      # bar 5
  foo.baz(6)      # f 6
Now who wants to say that 'js this' is quirky and complicated?

There are no comments on this comment yet.