Something always bothered me about how I do object oriented coding in Javascript. When there is a callback, I often want to refer to an object that was originally called a function, which forces me to do something like this:
MyClass.prototype.doSomething = function(obj, callback) { var me = this;
First, creating an extra variable has always seemed ... excessive for me. Also, I have to wonder if this can cause problems (circular links? Un-GCd objects?) By passing the variable "me" back to the callback.
Is there a better way to do this? Is this approach evil?
source share