Created
September 7, 2018 07:31
-
-
Save HashirHussain/540a98935037f4b2d8a351e19af468da 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
/*We know the purpose of classes in sense of programming concepts. | |
In JavaScript `class` is the makeover upon traditional prototype-inheritance. | |
*/ | |
//ES5 Approach: | |
function Person(first, last) { | |
this.first = first; | |
this.last = last; | |
} | |
Person.prototype.firstName = function() { | |
console.log(this.first); | |
} | |
Person.prototype.lastName = function() { | |
console.log(this.last); | |
} | |
Person.prototype.fullName = fucntion() { | |
console.log(this.first + ' ' + this.last); | |
} | |
var me = new Person('Hashir', 'Hussain'); | |
console.log(me.printName()); //Hashir Hussain | |
//ES6 Approach | |
class Person() { | |
constructor(first, last) { | |
this.first = first; | |
this.last = last; | |
} | |
firstName() { | |
console.log(this.first); | |
} | |
lastName() { | |
console.log(this.last); | |
} | |
fullName() { | |
console.log(this.first + ' ' + this.last); | |
} | |
} | |
var me = new Person('Hashir', 'Hussain'); | |
console.log(me.fullName); //Hashir Hussain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment