Created
May 19, 2015 03:58
-
-
Save tiagopog/693cfcd69fddda3b800d to your computer and use it in GitHub Desktop.
JavaScript ES6
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
// Old way... | |
function Person(name) { | |
this._name = name; | |
}; | |
Person.prototype.getName = function() { | |
return this._name; | |
}; | |
person = new Person('Foo'); | |
console.log(person.getName()); | |
// New way... | |
class Person { | |
constructor(name) { | |
this._name = name; | |
} | |
getName() { | |
return this._name; | |
} | |
} | |
person = new Person('Bar'); | |
console.log(person.getName()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment