Skip to content

Instantly share code, notes, and snippets.

@pbugnion
Last active April 23, 2020 23:00
Show Gist options
  • Save pbugnion/63cf43b41ec0eed2d0b7e7426d1c67d2 to your computer and use it in GitHub Desktop.
Save pbugnion/63cf43b41ec0eed2d0b7e7426d1c67d2 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Ricyteach
Copy link

Excellent, very clear-- thank you. Will that "modern" version run in most browsers?

I'm a very skilled Python guy, but I have written very little javascript, and what little I know is mostly the old syntax, I have never written, for example, typescript or used the newer ECMA 5, 6, 7, 8, 9 stuff (I assume that is what you have written there?).

I might try submitting a pull request to update the docs with this small tidbit. If I can feel confident enough I know what I am doing now (I believe I do).

@pbugnion
Copy link
Author

pbugnion commented Jun 12, 2019

Will that "modern" version run in most browsers?

No -- to get sufficient browser support, it needs to be transpiled to 'old' [*] JavaScript using a tool like Babel or typescript, and bundled using something like webpack.

A good heuristic is:

  • if you have a very simple frontend, then keeping it in 'old' JS is probably safest. If you have no experience of Babel and webpack, I'd expect it to take you a day or two just to get something working (based on my personal experience as a Python developer who had to learn JS that way).
  • if you are going to develop a rich frontend library, then the investment is worth it. 'New' transpiled JS is just nicer to write.

[*] here, 'old' JavaScript means JavaScript that can be executed by all the browsers you want to support. It's useful to note that this isn't well-defined: the latest version of Chrome will accept lots of modern syntax, while IE 11 won't. For instance, pasting the following in my chrome console works just fine:

class Hello {
    static prop = {
        a: 22
    }
}

Hello.prop
# {a: 22}

I might try submitting a pull request to update the docs with this small tidbit

Yes! That would be great! Jupyter widgets are purely maintained by the community -- there is no commercial company behind them, so we're very heavily reliant on contributions like these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment