Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this is weird when you use #call #39

Open
judofyr opened this issue Jun 6, 2018 · 2 comments
Open

this is weird when you use #call #39

judofyr opened this issue Jun 6, 2018 · 2 comments

Comments

@judofyr
Copy link

judofyr commented Jun 6, 2018

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 ???

Seems like there a different this when you invoke a function through #call.

@kares
Copy link
Collaborator

kares commented Jun 6, 2018

believe this is proper JS -> in the last case this is the global object :)

@judofyr
Copy link
Author

judofyr commented Jun 7, 2018

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants