Last active
May 10, 2017 21:37
-
-
Save BolajiOlajide/0575c2e23ba8545d9434fe912026da6f to your computer and use it in GitHub Desktop.
Different ways of defining classes in ES5 and also how to inherit from another 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
// class | |
var Person = function(name, gender) { | |
this.name = name; | |
this.gender = gender; | |
this.legs = 2; | |
} | |
Person.prototype.getName = function () { | |
return this.name; | |
} | |
// class | |
function Car() { | |
var make = 'mazda'; | |
var model = '323'; | |
var getMake = function () { | |
return make; | |
} | |
return { | |
getMake: getMake | |
} | |
} | |
// var femi = new Person('Femi Abolaji', 'male'); | |
function man(name, gender) { | |
this.name = name; | |
this.gender = gender; | |
} | |
man.prototype = new Person(); | |
var tunde = new man('Tunde will', 'male'); | |
tunde.getName(); | |
tunde.legs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment