javascript - How to determine parameter list of callback functions -
in d3.js, time pass callback function argument, e.g. in delay() below:
d3.select('body').selectall('div') .data(distances) .enter() .append('div') .html('.') .style('width', '10px') .style('opacity', 0) .transition() .delay(function(d, i) { return * 1000 })
question: how know callback function shall have 2 parameters: d , i. , in document specify 'd' should correspond datum , 'i' correspond index?
my question not limited d3.js js convention in general. e.g. in angular.js, found similar thing. e.g. in callback function passed then() below:
// simple request example: $http({ method: 'get', url: '/someurl' }).then(function successcallback(response) { // callback called asynchronously // when response available }, function errorcallback(response) { // called asynchronously if error occurs // or server returns response error status. });
how know (i.e. document specifies ) callback function supposed take argument , argument correspond response?
my question not limited d3.js js convention in general.
it has documented api method you're passing callback to. there's no other way know arguments callback called with — or when called, (if anything) it's expected return, etc.
for d3 example, it's defined in delay
documentation:
otherwise, if delay function, function evaluated each selected element (in order), being passed current datum
d
, current indexi
,this
context current dom element.
for angularjs example, then
promise function, documented here:
the promise api
...
methods
then(successcallback, errorcallback, notifycallback)
– regardless of when promise or resolved or rejected, calls 1 of success or error callbacks asynchronously result available. callbacks called single argument: result or rejection reason. additionally, notify callback may called 0 or more times provide progress indication, before promise resolved or rejected.
Comments
Post a Comment