Edit: I have to apologize, the problem I posted about actually does not exist in the code I posted, because I oversimplified it. I'll try to post something later.
Deletion would also be ok, but there are too many answers at present, so I cannot do it myself.
Edit2: Ok, here goes:
Let,
function F() {
this.field = "value" ;
var init = function(value) {
this.field = value ;
} ;
this.method = function() {
return this.field ;
} ;
init( arguments[0] ) ;
}
Now, instantiation of F
type,
var f = new F("newValue") ;
will set the value to the Window
object as this
points to it when called from the closure.
Binding this
to the Function
,
function F() {
var self = this ;
this.field = "value" ;
var init = function(value) {
self.field = value ;
} ;
this.method = function() {
return this.field ;
} ;
init( arguments[0] ) ;
}
will resolve the problem.
Still, what is the reason for this -- imho -- odd behaviour?