Created
November 7, 2019 08:22
-
-
Save christiannwamba/23de94980ce7c21d16f0d83acc2892fb to your computer and use it in GitHub Desktop.
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
/** | |
* Contructor Function to Class | |
*/ | |
// BEFORE | |
function Team(name) { | |
this.name = name; | |
this.count = 14 | |
} | |
Team.prototype.hire = function(num) { | |
return this.count += num | |
} | |
// AFTER | |
class Team { | |
constructor(name) { | |
this.name = name; | |
this.count = 14; | |
} | |
hire(num) { | |
return this.count += num; | |
} | |
} | |
/** | |
* Promise to Async-Await | |
*/ | |
// BEFORE | |
function fetchTeam(url) { | |
return fetch(url).then(res => console.log(res)).catch(err => console.error(err)) | |
} | |
// AFTER | |
async function fetchTeam(url) { | |
try { | |
const res = await fetch(url); | |
return console.log(res); | |
} | |
catch (err) { | |
return console.error(err); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment