0

Does passing the entire object as argument rather than just a property of it, in javascript, effect performance? For example:

<input type="button" onclick="getDetails(this)"/>

vs

<input type="button" onclick="getDetails(this.sourceIndex)"/>

even if I pass the sourceIndex property of 'this' object, I would retrieve the entire element from it in my function - getDetails(). I need advise on what exactly will be the effect in this particular case.

1 Answers1

3

I feel like profiling this would be overkill. Technically you're passing less on the second way but the performance hit/gain (if any at all) using either is negligible. At this point it's more of about maintainability. Normally you would attach the the event via JavaScript as well but if for some reason you can't and you will need the whole element anyway, going with the first one will save you the hassle of retrieving the element unnecessarily.

Ryan
  • 31
  • 3