Skip to content

Instantly share code, notes, and snippets.

@BolajiOlajide
Last active May 10, 2017 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BolajiOlajide/0575c2e23ba8545d9434fe912026da6f to your computer and use it in GitHub Desktop.
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
// 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