Lets take the following example of inheritance in javascript:
var Employee = function(name, salary) {
Person.call(this, name);
this.name = name;
this.salary = salary;
}
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;
Employee.prototype.doWork = function() {
alert('working!');
}
How about creating a Class and a super function so, that we could rewrite the previous code like this:
var Employee = Class({
extends: Person
constructor: function(name, salary) {
super(name);
this.salary = salary;
}
doWork: function() {
alert('working!');
}
});
The usage would be more or less analogous to ECMAScript 6 class:
class Employee extends Person {
constructor(name, salary) {
super(name);
this.salary = salary;
}
doWork() {
alert('working!');
}
}
It still takes a some time until every browser runs ECMAScript 6, so why not use such shorthand for class declarations? Would this have any real drawbacks? Are there any libraries doing this?