jquery - What is the concept behind javascript parameters? -
let me try explain weird confusion
i'm trying learn d3.js
. i'm seeing lot of functions odd kind of parameters (they odd @ least me).
d3.selectall("p").style("color", function(d, i) { return % 2 ? "#fff" : "#eee"; });
- what
d
doing here? why passed when it's of no use? - from
i
(along value) getting passed?
also following jan's tutorial , built fiddle. has odd function params:
.attr("cy", function(d) { return y(d.y) })
.delay(function(d, i) { return * del(math.random()) })
- from
d
(along value) getting passed?
what
d
doing here? why passed when it's of no use?
the style
function call callback specific set of arguments. fact callback doesn't happen need first of arguments doesn't change how style
call it. callback has accept argument, ignore it.
from
i
(along value) getting passed?
the style
function. it's calls callback, it's determines values of arguments callback receives.
here's example of function accepting , calling callback, clarify things. see comments:
// here's our function accepts callback, // d3's `style` accepts callback. function dosomething(callback) { // call callback 2 arguments, // random letter , random number: var letter = string.fromcharcode(65 + math.floor(26 * math.random())); var number = math.floor(math.random() * 100); callback(letter, number); } // call function, giving callback // makes use of both of arguments: dosomething(function(l, n) { console.log("first callback: letter is: " + l); console.log("first callback: number is: " + n); }); // call function, giving callback // uses second argument: dosomething(function(l, n) { console.log("second callback: number is: " + n); });
Comments
Post a Comment