I have promise code, how to convert it to callback code example
Example 1: convert functoin with call back to promise
const readFilePromise = () => {
return new Promise((resolve, reject) => {
fs.readFile(filePath, options, (err, data) => {
if (err) return reject(err)
resolve(data)
})
})
}
Example 2: promises and not callbacks
var Button = function(content) { this.content = content;};Button.prototype.click = function() { console.log(this.content + ' clicked');}var myButton = new Button('OK');myButton.click();var looseClick = myButton.click;looseClick(); // not bound, 'this' is not myButton - it is the global objectvar boundClick = myButton.click.bind(myButton);boundClick(); // bound, 'this' is myButton