JSFiddle - React, Tailwind, and code Playground
by Deepak Anand
JavaScript
// Compare super call behavior in constructor
// when using dojo/declare vs native classes
require([
"dojo/_base/declare"
], function(declare) {
// Dojo declared "classes"
var SuperClass = declare(null, {
constructor: function() {
console.log('dojo/declare: super')
}
});
var SubClass = declare(SuperClass, {
constructor: function() {
// super() call is not needed, it is implied
console.log('dojo/declare: sub')
}
});
var subclassInstance = new SubClass()
// ES6 classes
class SuperKlass {
constructor() {
console.log('Native: super')
}
}
class SubKlass extends SuperKlass{
constructor() {
// Subclass needs to call super() in order
// for the class to be properly initialized
super()
console.log('Native: sub')
}
}
var subKlassInstance = new SubKlass()
});