Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created November 7, 2019 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannwamba/23de94980ce7c21d16f0d83acc2892fb to your computer and use it in GitHub Desktop.
Save christiannwamba/23de94980ce7c21d16f0d83acc2892fb to your computer and use it in GitHub Desktop.
/**
* 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