Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to generate global, named javascript functions in coffeescript, for Google Apps Script
    text
    copied!<p>I'd like to write Javascript scripts for <a href="http://code.google.com/googleapps/appsscript/" rel="noreferrer">Google Apps Script</a> using CoffeeScript, and I'm having trouble generating functions in the expected form.</p> <p>Google Apps Script expects a script to contain top-level, named functions. (I may be using the wrong terminology, so I'll illustrate what I mean with examples...)</p> <p>For example, this function is happily recognised by Google Apps Script: </p> <pre><code>function triggerableFunction() { // ... } </code></pre> <p>... while this function is not (it will parse, but won't you won't be able to trigger it): </p> <pre><code>var nonTriggerableFunction; nonTriggerableFunction = function() { // ... }; </code></pre> <p>I've found that with CoffeeScript, the closest I'm able to get is the <code>nonTriggerableFunction</code> form above. What's the best approach to generating a named function like <code>triggerableFunction</code> above?</p> <p>I'm already using the 'bare' option (the <code>-b</code> switch), to compile without the top-level function safety wrapper.</p> <p>The one project I've found on the web which combines CoffeeScript and Google App Script is <a href="https://github.com/TobiaszCudnik/gmail-gtd-bot" rel="noreferrer">Gmail GTD Bot</a>, which appears to do this using a combination of back-ticks, and by asking the user to manually remove some lines from the resulting code. (See the end of the <a href="https://github.com/TobiaszCudnik/gmail-gtd-bot/blob/master/src/GtdBot.coffee" rel="noreferrer">script</a>, and the 'Installation' section of the <a href="https://github.com/TobiaszCudnik/gmail-gtd-bot#readme" rel="noreferrer">README</a>). I'm hoping for a simpler and cleaner solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload