0

This is a section of code from https://bl.ocks.org/mbostock/3014589

Why are () omitted after the functions assigned to "interpolate"? How is it different from with ()?

Thank you

var spaces = [
  {name: "HSL", interpolate: d3.interpolateHsl},
  {name: "HCL", interpolate: d3.interpolateHcl},
  {name: "Lab", interpolate: d3.interpolateLab},
  {name: "RGB", interpolate: d3.interpolateRgb}
];
user3562812
  • 1,751
  • 5
  • 20
  • 30

1 Answers1

3

Without the parentheses, you're referencing the function itself. If you put the ()'s, you're actually calling the function and returning the result (if any). So by putting the name of the function in there, whatever uses the object and references the interpolate attribute can evaluate that function. For example, see this post.

Community
  • 1
  • 1
Will Jobs
  • 362
  • 1
  • 11