Open judofyr opened 6 years ago
believe this is proper JS -> in the last case this
is the global object :)
Why isn't this
the global object in all of the examples? If I bind
to null
and call the function I get 123. There seems to be two different global objects in play here?
require 'rhino'
p Rhino::VERSION # => 2.0.4
ctx = Rhino::Context.new
ctx.eval('this.bar = 123');
p ctx.eval('(function() { return this.bar })()') # => 123 (as expected)
p ctx.eval('this.bar') # => 123 (as expected)
p ctx.eval('(function() { return this.bar })').call # => nil ???
p ctx.eval('(function() { return this.bar }).bind(null).call()') # => 123 (as expected)
Seems like there a different
this
when you invoke a function through #call.