|
|
|
|
|
by drinchev
2998 days ago
|
|
When comparing ES2015 and how it was before. I usually take the babel playground [1] and see what the closest alternative would be. For a simple es2015 it looks a bit more complicated than the prototype extension [2]. class Dog {
bark() { console.log( "Bark!" ); }
}
Compiles to : "use strict";
var _createClass = (function() {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function(Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
})();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var Dog = (function() {
function Dog() {
_classCallCheck(this, Dog);
}
_createClass(Dog, [
{
key: "bark",
value: function bark() {
console.log("Bark!");
}
}
]);
return Dog;
})();
1 : https://babeljs.io/repl/2 : https://babeljs.io/repl/#?babili=false&browsers=&build=&buil... |
|