This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//mock a fs Object | |
let fs = { | |
readFile: function(filename, cb){ | |
let randomTime = 100+Math.random()*1000>>0; | |
setTimeout(()=>{ | |
cb(`hello ${filename}`) | |
}, randomTime) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ES6 Class inherit example | |
class Person{ | |
sayName(){ | |
console.log(this.name); | |
} | |
} | |
class Classmate extends Person { | |
constructor(name){ | |
super() | |
this.name = name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = { | |
readFile: function(filename, cb){ | |
setTimeout(()=>{ | |
cb('hello') | |
}, 100) | |
} | |
} | |
let readFilePro = function(filename){ | |
return new Promise(function(resolve, reject) { | |
fs.readFile(filename, (data, err) => { |
NewerOlder