Created
November 12, 2019 11:41
-
-
Save darkmavis1980/40bc3e6b429e18187b52e6a4ca5ab7f1 to your computer and use it in GitHub Desktop.
Function constructor vs class
This file contains hidden or 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
// 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