dotnet/interactive

Polyglot Notebooks - Javascript - Cannot trigger functions from previously executed cells

Closed this issue · 3 comments

Describe the bug

When I try to call functions defined in previous cells, I'm not getting any output or errors. I'd like to be able to reuse functions defined in other cells. Is there a way to make this work?

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):
.NET Interactive
© 2020-2025 Microsoft Corporation
Version: 1.0.617701+fb2fd8022ab96c55fbaf34d5e1c8c61cb01690fc
Library version: 1.0.0-beta.25177.1+fb2fd8022ab96c55fbaf34d5e1c8c61cb01690fc
https://github.com/dotnet/interactive

  • OS
    • Windows 11
    • Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • Jupyter Lab
    • nteract
    • Visual Studio Code
    • Visual Studio Code Insiders
    • Visual Studio
    • Other (please specify)

Screenshots

If applicable, please add screenshots of the entire VS Code window.

Image

[Error] webview: Error when handing command [object Object]: ReferenceError: fun1 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun1 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: about is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined
[Error] webview: Error when handing command [object Object]: ReferenceError: fun2 is not defined

Image

You can assign it to a variable like this:

fun1 = function() { console.log("fun1"); }

Image

There's more information here on working with JavaScript in Polyglot Notebooks.

Thank you @jonsequitur ! That is helpful.