U
Une Bévue
i have two pices of code allready tested separately but when i want to
put them together i get a javascript error (doesn't depend on browser) :
Uncaught TypeError: Object function (s){
for(var i=0,l=this.length;i<l;i++){if(this===s){return true;}}
return false;
} has no method 'Update'
the code printed out comes from :
Array.prototype.include=function(s){
for(var i=0,l=this.length;i<l;i++){if(this===s){return true;}}
return false;
}
and the method 'Update' comes from the other pice of code, an M V C
ctriad constructors, to simplify :
function Model()
{
this.observers=new Array();
function Attach( Observer )
{
this.observers.push( Observer );
}
this.Attach=Attach;
.... about the "same" with Detach Observer )
function Notify()
{
for( var i in this.observers )
{
this.observers.Update( this );// HERE THE PROB
}
}
this.Notify=Notify;
....
}
the Update method is defined in the View part :
function View( Observable)
{
Observable.Attach( this ); // Observable is a new Model()
function Update( Observable )
{
var id=Observable.state.id;
switch( Observable.state.XHR.readyState )
{
...
}
}
this.Update=Update;
...
}
I don't understand clearly what's the problem...
I understand that this.observers is an Array and i want to had a method
include to the Object Array. The Update method applies to an object in
this array :
this.observers.Update( this );
clearly this.observers is a View( model)
may be this comes up because of mixing technics to add methods ?
does it means that i do have to use prototypr also for my constructors :
function Model() {...}
function View( Observable) { ... }
function Controller( Observable ) { ... }
for example for Model#Notify should I use something like :
function Model()
{
this.observers=new Array();
}
that's all, the methods being defined like that :
Model.prototype.Notify = function() {
for( var i in this.observers )
{
this.observers.Update( this );
}
}
any light appreciated !
put them together i get a javascript error (doesn't depend on browser) :
Uncaught TypeError: Object function (s){
for(var i=0,l=this.length;i<l;i++){if(this===s){return true;}}
return false;
} has no method 'Update'
the code printed out comes from :
Array.prototype.include=function(s){
for(var i=0,l=this.length;i<l;i++){if(this===s){return true;}}
return false;
}
and the method 'Update' comes from the other pice of code, an M V C
ctriad constructors, to simplify :
function Model()
{
this.observers=new Array();
function Attach( Observer )
{
this.observers.push( Observer );
}
this.Attach=Attach;
.... about the "same" with Detach Observer )
function Notify()
{
for( var i in this.observers )
{
this.observers.Update( this );// HERE THE PROB
}
}
this.Notify=Notify;
....
}
the Update method is defined in the View part :
function View( Observable)
{
Observable.Attach( this ); // Observable is a new Model()
function Update( Observable )
{
var id=Observable.state.id;
switch( Observable.state.XHR.readyState )
{
...
}
}
this.Update=Update;
...
}
I don't understand clearly what's the problem...
I understand that this.observers is an Array and i want to had a method
include to the Object Array. The Update method applies to an object in
this array :
this.observers.Update( this );
clearly this.observers is a View( model)
may be this comes up because of mixing technics to add methods ?
does it means that i do have to use prototypr also for my constructors :
function Model() {...}
function View( Observable) { ... }
function Controller( Observable ) { ... }
for example for Model#Notify should I use something like :
function Model()
{
this.observers=new Array();
}
that's all, the methods being defined like that :
Model.prototype.Notify = function() {
for( var i in this.observers )
{
this.observers.Update( this );
}
}
any light appreciated !