Published
Edited
Oct 13, 2021
Insert cell
Insert cell
{
let i = 0;
yield i;
while (true) {
yield Promises.delay(1000, ++i);
}
}
Insert cell
Insert cell
{
let i = 0;
yield i;
let interval = setInterval(() => {
i++;
}, 1000);
try {
while (true) {
yield i;
}
} finally {
clearInterval(interval); // ただし、再評価時に破棄されます。
}
}
Insert cell
Insert cell
Generators.observe(notify => {
let i = 0;
notify(i);
let interval = setInterval(() => notify(++i), 1000);
return () => clearInterval(interval);
})
Insert cell
Insert cell
// このセルを実行してください
a = [1, 2, 3, 4]
Insert cell
// 次に、このセルを数回実行してください
a.splice(0, 1)
Insert cell
// 最後に、このセルを実行してください
a.length
Insert cell
Insert cell
b = [1, 2, 3, 4]
Insert cell
c = {
let copy = b.slice();
copy.splice(0, 1);
return copy;
}
Insert cell
c.length
Insert cell
Insert cell
Insert cell
myObject = ({hi:'Tom'})
Insert cell
(myObject.key = Date.now())
Insert cell
myObject
Insert cell
Insert cell
myObjectWithKey = ({ key: Date.now(), ...myObject })
Insert cell
Insert cell
Insert cell
Insert cell
myObjectWithoutHi = _.omit(myObjectWithKey, 'hi')
Insert cell
Insert cell
Insert cell
{
let i = 0;
for (; i < 10; i++) {
yield i;
}
return i;
}
Insert cell
Insert cell
{
let i = 0;
for (; i < 10; i++) {
yield i;
}
yield i;
}
Insert cell
Insert cell
{
function* hasReturnValue() {
yield "a";
yield "b";
return "The result";
}
let finalValue = yield* hasReturnValue();
yield finalValue;
}
Insert cell
Insert cell
html`<div id='my-fun-element'></div>`
Insert cell
document.querySelector('#my-fun-element').innerText = 'What a fun element!'
Insert cell
Insert cell
myElement = html`<div></div>`
Insert cell
(myElement.innerText =
"これは私の要素で、常に永遠に機能し続けることが分かっています。")
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, 100));
const x = d3.scaleLinear().domain([0, 500]).range([0, width]);
const y = d3.scaleLinear().range([20, 80]);

svg
.append("path")
.datum(d3.range(500).map(() => Math.random()))
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr(
"d",
d3
.line()
.x((d, i) => x(i))
.y(y)
);

return svg.node();
}
Insert cell
viewof randomize = html`<button>ランダムに色を変更</button>`
Insert cell
randomize, d3.select(chart).select('path').attr('stroke', `hsl(${Math.random() * 100}, 100%, 50%)`)
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more