Object created from code block is not working on other web dev platform

I’m not able to get the following code show on this notebook to work on CodeSandBox test:

sceneObject = {
const scene = new THREE.Scene(); // Create scene
scene.background = new THREE.Color(‘black’); // Sets scene background color
return scene;
}

I got the following error:

May I ask if this way of creating an object through a code block is particular to notebook on Observable only?

Hi @oat! Yes, what you see in the notebook is a dialect we call “Observable JavaScript”.

The code for the sceneObject cell that you see in the notebook eventually gets compiled to

function _sceneObject(THREE)
{
  const scene = new THREE.Scene(); // Create scene
  scene.background = new THREE.Color('black'); // Sets scene background color
  return scene;
}

(You can inspect the compiled cell code in this notebook.)

Observable’s Runtime takes care of resolving dependencies between cells and running them again when values change. This behavior is referred to as reactive dataflow.

1 Like

Thank you for the detailed explanation.

I need to go through the basics of how notebook works on Observable.

1 Like

@oat - if you want Observable Notebooks in VS Code then you can try: Observable JS - Visual Studio Marketplace

1 Like