score:4
yep, as the commenters have suggested, this is a syntax that's particular to observable. what you're seeing a cell that uses a block, as mentioned in the introduction to code.
how you can think of this relative to other javascript is that it's kind of like an iife, but with the added consideration that, if it references other cells, it automatically resolves them. so in vanilla javascript, this would be like:
chart = (() => {
const svg = d3.select(dom.svg(width, height));
const g = svg.append("g")
.selectall("g")
.data(bins)
.join("g");
// [...]
return svg.node();
})()
in fact, that's roughly what they compile to. the particular syntax is that way because it's meant to be clear that it's code that runs when references change - see how observable runs for details on that. unlike an iife, a cell in observable might run multiple times, if something that it references, like a generator or promise, changes.
Source: stackoverflow.com
Related Query
- Return value in non-function Javascript code block
- D3 JavaScript return data value plus variable from anonymous function
- How to fix d3 parsing error when using function and return value to set "d"?
- Why javascript function return NaN value?
- How to return a value from a function, which is generated inside a callback function within?
- Javascript not waiting for return value
- d3.js return value of function always undefined
- Pass value from button in HTML to function in Javascript
- Getting same value from javascript function
- d3 filter the return function value force layout
- Drupal javascript block does not display info window - same code in node does
- Javascript library d3 call function
- Converting Javascript function to Typescript including getComputedTextLength()
- What is the shorthand in d3 for the identity function ("function(d) { return d; }")?
- d3.js undefined data value in callback function click event
- Javascript code editor with intelligence
- Javascript - function argument
- Return value based on max/min of another value in the same object
- draw a horizontal line in d3. the following code shows a line drawn based x n y value of pixels
- JavaScript d3 passing arguments into a function that references d3.event.y
- Translate d3.js JavaScript function to CoffeeScript
- Find max/min value in a Javascript set
- Javascript - How to pass original object to callback function
- d3: will selection.style('font-size') always return a value in px?
- Javascript function returns undefined
- Javascript to access the x/y value of svg transform translate
- Probability density function with javascript d3 and dc
- javascript / d3 - passing parameters to a function
- How to send this D3.js element to another element's on-click function in this recursive Javascript
- Call JavaScript function from SVG file
More Query from same tag
- d3 not being found from plotly
- d3.groups by multiple keys given array of of keys
- Draw a vertical line in angular-nvd3 scatter chart
- How to create an y axis containing hours from noon to noon on the next day
- d3.js scatterplot with different colors and symbols - issues encountered
- d3 lat/long points are not lining up with map
- Create tree hierarchy from csv in d3.js
- d3 can't edit children css
- d3.js -- Axis label help (from v3 to v4)
- Get the center of an arc path and get the x and y that relates to in screen coords
- D3.js time scale quirk with "11 PM" values
- d3.js rectangle feature plotted as arc in Mollweide projection
- Make the Click event unavailable during animations
- Draw graph for child nodes on click of the node of tree pattern in d3.js
- Colour nodes in D3 force layout
- d3 brush not resetting when removed
- Get location along a path or line upon click in d3
- X-Axis Date Formatting in Rickshaw
- D3 line .defined() with different array
- Understanding D3 data join using the new syntax - Array data is update but DOM not
- D3 Tree update color of nodes dynamically
- Change rectangles to circles for sankeyNetwork in networkd3
- D3 Graphviz d3.select.graphviz is not a function
- SVG <g> element dragging causes flickering issue using d3
- Display yaxis on left in d3
- How do I filter a stacked line chart by stack in dc.js?
- D3 v4 Zoom x-Axis Zooming and Panning Issue
- d3.js undefined in Meteor
- Being able to select text with zoom?
- band zoom in d3 for two graph in html