Not true. JavaScript's `this` binding is absolutely not the only way to do it.
In Ruby:
class Foo
def hello
return proc { self }
end
end
puts Foo.new.hello.call #=> #<Foo:0x10e56c840>
In Python: class Foo(object):
def hello(self):
def zoo():
return self
return zoo
zoo = Foo().hello()
print(zoo()) #=> <__main__.Foo object at 0x102453f90>
In Ruby, blocks carry the original `self` as part of their variable scope. Rubinius exposes this if you want to poke around: ruby-1.9.3-head :007 > x = proc {}
=> #<Proc:0x1598@(irb):7>
ruby-1.9.3-head :008 > x.block.scope.self
=> main
In Python, it's a side-effect of the fact that you need to explicitly define `self` as a parameter.In Ruby, it's possible to override the `self` in a block using instance_eval, just as it's possible to explicitly define a `this` in JavaScript using `.call`.
The difference is that in JavaScript, the callee is always responsible for deciding what the `this` should be (often implicitly), where in Ruby and Python, the function's original binding includes its `self`.
edit: another way to put it would be that Coffee's fat arrow fix is the default in Ruby and Python.