I was looking at the source code of a JavaScript library and encountered something like this in a class definition:
var MyClass = function() {
function doSomething() {
// function definition
}
this.doSomething = function() {
doSomething();
};
}
So, my question is: is there any reason someone would do this instead of simply assigning the function to the object method like this:
this.doSomething = doSomething;