The example of includes of data in ES6 is incomprehensible. There are no parameters when defining, but the call can pass parameters.

related codes

const contains = (() =>
  Array.prototype.includes
    ? (arr, value) => arr.includes(value)
    : (arr, value) => arr.some(el => el === value)
)();

contains(["foo", "bar"], "baz"); // => false

this is an example I saw in Ruan Yifeng"s ES6 tutorial. I can"t understand how the parameters are passed when the function is called.

Jul.14,2021

this code is too refined. Let's extract the key points:

 
The contains function defined by 

returns one function and defines two parameters;

if the original method of the array has a method of includes, it directly returns (arr, value) = > arr.includes (value) where two parameters arr, value;

are defined.

if there is no includes method, (arr, value) = > arr.some (el = > el = value) is returned, where two parameters arr, value;

are also defined.

and there are anonymous expressions outside contains that (), is executed immediately;

when calling contains (['foo',' bar'], 'baz'), it is equivalent to passing [' foo', 'bar'] to arr,' baz' to value.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b385e5-344ba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b385e5-344ba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?