Jun. 30th, 2016

orleanz: (main)
А бывает ли такое в Германии, когда полицейская машина за тобой сзади едет некоторое время, а потом сваливает (никак не проявившись), и ты потом по почте получаешь штраф за превышение скорости?

Хочу все знать. Вчера за нами пару минут ехала полицейская машина по автобану (скорость была 69 кмч при разрешенных 60, из-за стройки) а потом резко обогнала и ушла вперед.
orleanz: (main)
http://babeljs.io/docs/learn-es2015/

Destructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup foo["bar"], producing undefined values when not found.

// list matching
var [a, ,b] = [1,2,3];
a === 1;
b === 3;

// object matching
var { op: a, lhs: { op: b }, rhs: c }
       = getASTNode()

// object matching shorthand
// binds `op`, `lhs` and `rhs` in scope
var {op, lhs, rhs} = getASTNode()

// Can be used in parameter position
function g({name: x}) {
  console.log(x);
}
g({name: 5})

// Fail-soft destructuring
var [a] = [];
a === undefined;

// Fail-soft destructuring with defaults
var [a = 1] = [];
a === 1;

// Destructuring + defaults arguments
function r({x, y, w = 10, h = 10}) {
  return x + y + w + h;
}
r({x:1, y:2}) === 23
Default + Rest + Spread
Callee-evaluated default parameter values. Turn an array into consecutive arguments in a function call. Bind trailing parameters to an array. Rest replaces the need for arguments and addresses common cases more directly.

function f(x, y=12) {
  // y is 12 if not passed (or passed as undefined)
  return x + y;
}
f(3) == 15
function f(x, ...y) {
  // y is an Array
  return x * y.length;
}
f(3, "hello", true) == 6
function f(x, y, z) {
  return x + y + z;
}
// Pass each elem of array as argument
f(...[1,2,3]) == 6

Profile

orleanz: (Default)
orleanz

December 2018

S M T W T F S
      1
2345678
9101112 131415
16171819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 1st, 2025 10:37 am
Powered by Dreamwidth Studios