I did a pretty code:

var Square = function(id,order,color,state) {

this.id = id;
this.order = order;
this.color = color;
this.state = state;
this.connected = false;

MongoClient.connect(config.mongoURL, (function(err, db) {
this.connected = true;
this.db = db; //db
this.collection = db.collection("squares"); //collection
}).bind(this));
}

Square.prototype.connectDB = function(callback){

(function(that){
MongoClient.connect(config.mongoURL, function(err, db) {
 console.log("connected");
 this.connected = true;
this.db = db; //db
this.collection = db.collection("squares"); //collection

//callback(that);
callback();

});

})(this);
}


Square.prototype.test = function(){
console.log("test");
}

//export data
Square.prototype.exportData = function(){

var rtArr = {
id:this.id,
order:this.order,
color:this.color,
state:this.state
}; 

return rtArr;
}

//save datas to mongo
Square.prototype.saveData = function () {

if (this.collection){

*var doc = this.exportData();*
this.collection.insert(doc,function() {
console.log('inserted');
 });
}else{
this.connectDB(this.saveData);
}
}

var square = new Square(6,1,'red',1);
square.saveData();

When I run this code, that display:

throw err
                    ^
TypeError: Object #<Object> has no method 'exportData'

Why it can not understand *var doc = this.exportData(); ?*
*
*
Someone can help me ? Thank you very much

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to