javascript - fill in the values of an array using the array.map -
i'm trying understand code uses array.map()
var char_set = array.apply(null, array(256)).map(boolean.prototype.valueof, false);
the above code creating array indexes 0-255
, each value set false
could explain how array being created map
method. syntax of map
method
arr.map(callback[, thisarg])
in case thisarg
set false
?
array.apply(null, array(256))
: create array of 256 elements value undefined in elements
map(…)
: used initialize values false
the first argument in map
takes callback function; boolean.prototype.valueof
function act callback.
true.valueof()
returns true
has invoked thisarg.
|
---------- true thisarg
false.valueof()
returns false
has invoked thisarg.
|
---------- false thisarg
when map(boolean.prototype.valueof, false)
invoked each element in array pass false
this
boolean.prototype.valueof
method. invoking false.valueof()
hence returns false
.
thus map(boolean.prototype.valueof, false)
equivalent to:
map(function(item){ return false.valueof() });
Comments
Post a Comment