24. var color = "Red"
var browsers = { fx: "Firefox", op: "Opera" }
var secret = `${color} Panda is ${browsers.fx}!
${color} Browser is ${browsers.op}!`
// ECMAScript 5th
// 猟忖双はひたすら + 處麻徨でBY
secret = color + " Panda is " + browsers.fx + "!n" +
color + " Browser is " + browsers.op + "!"
25. var tag = `<a href="...">Can't stop using ES6!</a>`
var re = `"[^"]*"|'[^']*'`
var list =
`<ul>
<li>firefox
<li>red panda
<li>lesser panda
<li>petit panda
</li>`
26. function panda(s = "lesser") {
return `${s} panda`
}
panda() === "lesser panda"
panda("red") === "red panda"
// ECMAScript 5th
function panda(s) {
if (s === undefined) {
s = "lesser"
}
return s + "panda"
}
27. function log(x, y, ...rest) {
console.log(x, y, rest)
}
log(1, 2, 3, 4, 5) // 1 2 [3, 4, 5]
log(0) // 0 undefinded []
// ECMAScript 5th
function log(x, y) {
var a = Array.prototype.slice.call(arguments, 2)
console.log (x, y, a)
};
28. var array = [ "hello", true, 7 ]
var params = [ 1, 2, ...array ]
sum(1, 2, ...params) === 9
var str = "fox"
var chars = [ ...str ] // [ "f", "o", "x" ]
// ECMAScript 5th
var array = [ "hello", true, 7 ]
var params = [ 1, 2 ].concat(array)
sum.apply(null, [ 1, 2 ].concat(params)) === 9
var str = "fox"
var chars = str.split("") // [ "f", "o", "x" ]
29. [a, b] = [b, a]
var [c,d] = (function f() { return [1,2]; })()
var [e,,[x,y],z=100] =[3,4,[10,20]]
30. var fx={ name:"Firefox", vendor:"Mozilla", ver:26 }
var ch={ name:"Chrome", vendor:"Google", ver:31 }
var browsers={ firefox: fx, chrome: ch }
var { name: n, ver: v } = fx // -> n="Firefox", v=26
(function ({ vendor: ven }) {
console.log(ven)
})(fx); // -> "Mozilla"
39. {
let a = 1, b = 10;
let (a = 100, c = 300) console.log(a); // -> 100
for (let a=0; a<3; a++) {
console.log(a+b); // -> 10, 11, 12
}
console.log(a); // -> 1
}
console.log(a); // 〜 ReferenceError: a is not defined
40. var browser = "Edge";
{ // block scope
let browser = "Firefox";
}
browser === "Edge";
// ECMAScript 5th
// 篳のスコ`プはv方スコ`プしか贋壓しなかった
var browser = "Edge";
(function(){ // function scope hack...
var browser = "Firefox";
})()
browser === "Edge";
46. function Person(){
this.age = 0
setInterval(() => {
this.age++ // this は Person オブジェクト
}, 1000)
}
var p = new Person()
49. function doFirstAsync(fileurl) {
return new Promise(function(resolve,reject) {
$.ajax({
src: fileurl, dataType: "json"
}).done(function(data){
resolve(data);
});
}
}
async function task(param) {
await new Promise((resolve) => {
setTimeout(resolve,1000);
});
let first = await doFirstAsync(".../first.json")
let second = await doSecondAsync(".../second.json")
let third = await doThirdAsync(".../third.json")
// ...函誼したデ`タを聞って弼?I尖
};