私はES6で実験しています。特に、クラスと継承。クラスApple
では、拡張しPolygon
ます。Polygon
のメソッドを拡張sayName()
して、console.log に出力したい。
traceur で実行すると、次のようになりますundefined
。console.log(foo);
class Polygon {
constructor(height, width) { //class constructor
this.name = 'Polygon';
this.height = height;
this.width = width;
}
sayName() { //class method
return 'Hi, I am a', this.name + '.';
}
}
class Apple extends Polygon {
constructor(length) {
super(length, length); //call the parent method with super
this.name = 'apple';
}
sayName() {
var foo = super();
console.log(foo);
}
}
let d = new Apple(5);
d.sayName();
トレーサー:
System.register("class", [], function() {
"use strict";
var __moduleName = "class";
function require(path) {
return $traceurRuntime.require("class", path);
}
var Polygon = function Polygon(height, width) {
this.name = 'Polygon';
this.height = height;
this.width = width;
};
($traceurRuntime.createClass)(Polygon, {sayName: function() {
return 'Hi, I am a', this.name + '.';
}}, {});
var Apple = function Apple(length) {
$traceurRuntime.superConstructor($Apple).call(this, length, length);
this.name = 'apple';
};
var $Apple = Apple;
($traceurRuntime.createClass)(Apple, {sayName: function() {
var foo = $traceurRuntime.superConstructor($Apple).call(this);
console.log(foo);
}}, {}, Polygon);
var d = new Apple(5);
d.sayName();
return {};
});
System.get("class" + '');
- どうすればクラスで優秀になり、
sayName()
ショーを価値あるものにすることができますか?Apple
console.log(foo)
- traceur がコンパイルされたコードを表示すると思っていましたが、そうではありませんでした。たとえば、
$traceurRuntime.createClass()
これらのコンストラクターがどのように作成されているかを理解するのに役立ちません。コンパイルされたコードを表示するために traceur を間違って使用していませんか?