Learn ES6
class Foo {
constructor(x, y) {
this.x = x;
this.y = y;
}
bar() {
return this.x + this.y;
}
}
var Foo = (function () {
function Foo(x, y) {
this.x = x;
this.y = y;
}
_prototypeProperties(Foo, null, {
bar: {
value: function bar() {
return this.x + this.y;
},
writable: true,
enumerable: true,
configurable: true
}
});
return Foo;
})();
var template = `
<div class="hoge">
<h1>hogehoge</h1>
<p>tempalte string</p>
</div>
`;
文字列改行できる
var template = "\n<div class=\"hoge\">\n
<h1>hogehoge</h1>\n
<p>tempalte string</p>\n</div>\n";
文字列改行できる
var width = 200;
var height = 100;
var html = `<div
style="width: ${width}px; height: ${height}px;"
>`;
変数展開も
var width = 200;
var height = 100;
var html = "<div" +
"style=\"width: " +
width + "px; height: " +
height + "px\">";
変数展開も
var func = (x, y) => {
return x + y;
}
var func = x => {
return x + 10;
}
var func = x =>
x + 10;
var func = () => {
return 10;
}
function書かなくてよい
var func = function (x, y) {
return x + y;
};
var func = function (x) {
return x + 10;
};
var func = function (x) {
return x + 10;
};
var func = function () {
return 10;
};
function書かなくてよい
var obj = {
func(x, y) {
return x + y;
}
};
コロンいらず
var obj = {
func: function func(x, y) {
return x + y;
}
};
コロンいらず
var func = (x, y = 5) => {
return x + y;
}
func(5); // => 10
引数の値にデフォルトを設定できる
var func = function (x) {
var y = arguments[1] === undefined ? 5 : arguments[1];
return x + y;
};
func(5); // => 10
引数の値にデフォルトを設定できる