function Foo() {
//...
for(var i=0; i<10; i+=1) {
let tmp = i;
console.log(tmp); // 0, 1, 2...
}
//...
console.log(i); // 10
console.log(tmp); // undefined
}
var Point2D = new StructType({ x: uint32, y: uint32 });
var Color = new StructType({ r: uint8, g: uint8, b: uint8 });
let Pixel = new StructType({ point: Point2D, color: Color });
let Line = new ArrayType(Pixel, 2);
let line = new Line({
{
point: { x: 10, y: 10},
color: { r: 255, g: 255, b: 255}
},
{
point: { x: 200, y: 30},
color: { r: 0, g: 100, b: 255 }
}
});
var { r, g, b } = line.color;
let [x, y] = circle.center;
let [a, b] = [b, a];
function king_of_the_north(who) {
return is_the_new_king(who || 'john-snow.gif');
}
after
function king_of_the_north(who='john-snow.gif') {
return is_the_new_king(who);
}
function all_kings_of_the_north() {
var kings = Array.prototype.slice.call(arguments);
kings.forEach(function(king){
king.i_am_the_king();
});
}
after
function all_kings_of_the_north(...kings) {
kings.forEach(function(king){
king.i_am_the_king();
});
}
[1,2,3].map(function(i){
return i*i;
});
[ for (i of [1,2,3]) i*i ]
function* fibonacci() {
let [prev, curr] = [0, 1];
for (;;) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
let seq = fibonacci();
console.log(seq.next().value);
console.log(seq.next().value);
console.log(seq.next().value);
var handler = {
get: function(myProxy, name){
return true;
}
};
var king_of_the_north = Proxy.create(handler);
king_of_the_north.is_the_king; // true
king_of_the_north.is_the_king = false; // Error
var john_snow = {
is_king: true,
really: function() {
return !john_snow.is_king;
}
};
var kings_of_the_north = new WeakMap();
kings_of_the_north.set(john_snow, john_snow);
kings_of_the_north.get(john_snow);
kings_of_the_north.get(john_snow).is_king;
kings_of_the_north.get(john_snow).really();
//------ kings.js ------
var kings = {
john: {
is_king: true
}
}
function is_king() {
return kings.john.is_king;
}
export { kings, is_king };
//------ main.js ------
import { is_king, kings } from 'kings';
//------ kings.js ------
var K = {
kings: {
john: {
is_king: true
}
},
is_king() {
return kings.john.is_king;
}
}
export default K;
//------ main.js ------
import K from 'kings';