JavaScript Functionality and Speciification?

Drafts utilises the OS’s “JavaScript core” version. Please note that it has not document object model like a browser, so functions for Windows, etc. are not available.

For importing code see Drafts’ version of the require function.

Drafts will support custom classes.

Your class definition is defining a call to a parent to construct it, but you never define what the parent class is, so as it stands that code would not work. If you use the rectangle and square example from the MDN page on super, where square extends rectangle, that looks to work fine.

Apple defines the documentation for JavaScript core. Drafts documentation can be found at https://scripting.getdrafts.com. As for a single unified specification of what is in there, no there isn’t. It can vary by the OS the user is using, because the core JavaScript version varies. We’ve seen evidence of this in terms of some forum users not having access to replaceAll due to the age of their OS.

How you write your actions is up to you. There are certainly ways to do things quickly without writing a single line of code. There are ways to do things in code that cannot be done any other way. Oftentimes, there is good reason to mix the two. This could be for speed of creation, maintenance ease of settings for non-coders, etc.

That is indicating a syntax error rather than an execution error. It is there just as a helper in the simple editor. Just keep an eye on it as you code.

Things you might like to consider are writing your code in a draft initially or an external editor with more JavaScript coding support. There’s some detailed discussion in this thread of how I do it that I think several others follow also.

Hope that helps.

5 Likes