Want more features on Pastebin? Sign Up, it's FREE!
Guest

q11990291

By: a guest on Aug 16th, 2012  |  syntax: JavaScript  |  size: 0.80 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function object() {
  2.  
  3. this.myProp1 = null;
  4. this.myProp2 = null;
  5.  
  6. this.myProp3 = getProp3Calculation(); //from global calculation
  7.  
  8. this.init = function([params], callback){
  9.     var that = this;      
  10.  
  11.  
  12.     var data = loadData(params);
  13.  
  14.     var model = [Mongoose Schema];
  15.     model.findOne({name: value}, function (error, document) {
  16.         if (!error && document){
  17.             callback(document, 'Success');
  18.         }
  19.         else{
  20.             callback(null, 'Error retrieving document from DB');
  21.         }
  22.     });
  23.  
  24.     //if asynchronous the following code will go into your loadCompletedHandler
  25.     //but be sure to reference "that" instead of "this" as "this" will have changed
  26.     that.myProp1 = data.Prop1;
  27.     that.myProp2 = data.Prop2;
  28.  
  29. };
  30.  
  31. [more functions and props for the object]
  32.  
  33. }
clone this paste RAW Paste Data