TIL Class Versus Function Prototypes
POSTED ON:
TAGS: javascript classes prototype
This is the same:
// Class Version
class Person {
constructor (name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
incrementAge() {
this.age += 1;
}
}
// function version
function Person(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
Person.prototype.incrementAge = function() {
return this.age =+ 1;
}
REFERENCE:
Must know JavaScript for react developers
Related TILs
Tagged: javascript