Skip to content

Instantly share code, notes, and snippets.

@darkmavis1980
Created November 12, 2019 11:41
Show Gist options
  • Save darkmavis1980/40bc3e6b429e18187b52e6a4ca5ab7f1 to your computer and use it in GitHub Desktop.
Save darkmavis1980/40bc3e6b429e18187b52e6a4ca5ab7f1 to your computer and use it in GitHub Desktop.
Function constructor vs class
// These are equals
class Test {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}
const t = new Test('alex');
console.dir(t);
function Test2(name) {
this.name = name;
return this;
}
Test2.prototype = {
getName: function() {
return this.name;
}
}
const t2 = new Test2('steve');
console.log(t2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment