Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Returns data from file if cached, caches data if not cached
  2. AFile.prototype.get = function () {
  3.     var proxyThis = this; // UGLY
  4.     if (this.data === "") {
  5.         console.log(this.filename + " not loaded..");
  6.         return fs.readFileAsync(this.filename).then(function (d) {
  7.             proxyThis.data = d;
  8.             console.log("Loading complete");
  9.             return d;
  10.         });
  11.     } else {
  12.         return Promise.resolve(this.data);
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement