I am getting a TypeError by calling this code:
player = new Player({name:''});
Player = MeteorModel.extend({
schema:{
name:{type:String,},
value:{}
},
belongsTo:{
meteorCollection:'', //which collection to add to
methodName: '' //which method to save on server side
},
print: function(){
console.log(this);
},
create: function(prototype){
this.fields.name = prototype.name;
this.type = prototype.type;
return this;
},
validate: function(){
return true;
}
});
var MeteorModel = function(){
this.extend = function(prototype){
this.model = prototype;
return this;
}
};
What should I make of this JavaScript TypeError:
TypeError: Object function(){
this.extend = function(prototype){
this.model = prototype;
return this;
}
}
has no method 'extend'
it has a function named extend right there? What's wrong?
the way I solved it:
I changed my code to this
var MeteorModelFunction = function(){
this.extend = function(prototype){
this.model = prototype;
return this;
}
};
MeteorModel = new MeteorModelFunction();
So I used the new keyword, as suggested. Frankly, this seems a little stupid, because I called new with "new Player()", but it works. Also, thanks JS for interlacing the terms "methods" with "functions".
Aucun commentaire:
Enregistrer un commentaire