Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

x.someFunction.call(x)

 
steve claflin
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see a lot of online code using this structure, most notably in references to Ajax in Action, in particular; things like: While I understand how call works, what I can't figure out is why it is needed in this situation.

The code in my subject line seems to me to be exactly the same in effect as:
It would make sense to me if it were:
Am I missing something here?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what you've posted, the need for call() in this case is unnecessary. It's not wrong, just unnecessarily wordy.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to remember the exact code since I do not have it in front of me, but I think it is actually needed in that situation since this.onerror can be set in a different scope since it can be a reference to an outside method. It has been awhile since I looked at Dave's Ajax stuff.

Eric

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic