JavaScript Functionality and Speciification?

So I’ve started fiddling with the actions and syntaxes, and have begun to write my own miniature library of common constants, functions, and classes. Now there are many different versions of JavaScript that exist, and multiple different ways of importing code.

I initially thought to use the export/import functionality, but it didn’t seem to work, so I used require(“lib-common.js”) which seemed to do exactly what I wanted. For the built in JavaScript objects, I use the MDN JavaScript reference, as the Drafts Scripting Reference does not list all of the standard methods and standard classes. I have a couple questions:

  1. Does Drafts support custom classes?

    class newClass
    constructor() { super(); }

  2. Is there a defined specification of which features exist and which do not? I’m writing Syntaxes for a variety of languages and creating actions to sync my workspaces across multiple PC’s and other programs.

  3. Should I be using multiple action steps that do what I want more directly? I’ve been writing all my steps in JavaScript.

  4. When I get the “:bangbang:“ in the corner due to a syntax error, is there any way to see the error without pressing save & close, then executing the action?

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 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.


Thank you, that explains much of it. I am using Drafts to code, with an extended Javascript+ syntax with Drafts objects in it. I appreciate the helpfulness.

Could you explain what that is? I have never heard of “Javascript+” (Googling didn’t help :confused:), or of anyone bringing Drafts objects into anything else in any way.

It certainly sounds intriguing.

1 Like