Javascript Classes in MaxMSP

Fynn Konig's icon

Hey there everyone,

I´m just trying out the javascript for Max implementation. However, I don´t seem to find anything on how to create classes. When I try to define one with the "class classname {}" Syntax, I get the following error:

js: BPMMachine.js: Javascript SyntaxError: missing ; before statement, line 6

Besides that I didn´t find any information or examples with javascript classes. Hoping for you to help me out, maybe I´m just missing something really simple?

Regards!

Fynn Konig's icon

Maybe I´ve postet this too early, seems the whole ES6 Syntax doesnt work as its not implemented?! Found this interesting page:
https://cycling74.com/forums/any-plans-to-update-support-for-recent-versions-of-js
Guess I´l have to live with it then...

Trevor being Trevor's icon

For those in the future, I found this tutorial very helpful for learning the old syntax and techniques to write classes in a Max js object...
https://www.newthinktank.com/2015/09/object-oriented-javascript/

Shaikat Hossain's icon

Has there been any talk of upgrading Javascript support to more recent versions of the language? It would be very helpful to be able to use classes.

Shakeeb Alireza's icon

You can always transpile to the Max version of js from a more recent version or Typescript:

tiago morais morgado's icon

Keep your project streamlined by using shells.js on a high-performance system. Instead of relying on MaxMSP’s node.script, which only handles a single script at a time, use shx.exec("node myscript.js") to run each module as needed. Set up a two-element list: the first element specifies the target script, and the second defines the expected behavior. This approach offers more flexibility and control over module routing and execution.

you can check for a paste of a prototype for doing something like this here

tyler mazaika's icon

See: Max 9 and the [v8] object.