Using the following bit of code:
function Node(){
....
function foo(request){
for (var name in this ) {
log(name +" is "+this[name]);
if(!(name == 'all' || typeof this[name] == 'function')){
request[name] = this[name];
}
}
return ...
};
}
I was surprised that when the private function foo
is called this
doesn't seem to refer to the containing object (an instance of Node
). Why is that ?
Of course I could have something like:
function Node(){
var ref = this;
....
}
and use ref
as this
in foo
, but is there a way of declaring private methods for which this
is a reference to the containing object?