Hacker News new | ask | show | jobs
by akdubya 5421 days ago
The underscore.js source (http://documentcloud.github.com/underscore/) also serves as a great primer on the effective use of 'this'. My rule of thumb is to never rely on 'this' unless 1) the function is already bound to an object or 2) I have explicitly set the binding via bind, call or apply. When in doubt favor explicit argument passing.
1 comments

In general, you can use explicit argument passing or closing over what you need. I tend to use closures to get information from my current scope to a callback, although that doesn't always work in heavily object-oriented code.