Google Apps Script Javascript Standard Support [duplicate] - javascript

This question already has answers here:
Which Edition of ECMA-262 Does Google Apps Script Support?
(2 answers)
Closed 2 years ago.
Simple question: Can anyone point to a resource or knows anything about which standard of Javascript is supported in Google Apps Script?
I assume naturally that ES5 is fully supported, but what about ES6 (and even 7)?
Note: I mean the built-in code editor, which will appear if you open a Spreadsheet (for example), and click Tools > Script editor...

According to the docs Apps Script is based on JavaScript 1.6.
This table explains the correlation to the ES standards.

From https://developers.google.com/apps-script/guides/services/#basic_javascript_features (January 27, 2019)
Basic JavaScript features
Apps Script is based on
JavaScript 1.6,
plus a few features from
1.7 and
1.8.
Many basic JavaScript features are thus available in addition to the built-in
and advanced Google services: you can
use common objects like
Array,
Date,
RegExp,
and so forth,
as well as the
Math and
Object
global objects. However, because Apps Script code runs on Google's servers (not
client-side, except for HTML-service pages),
browser-based features like DOM manipulation or the
Window API are not
available.

In the native editor it appears you are limited to an earlier version of JS (~ES5).
There is an official tool called "Clasp" though, which lets you write typescript (.ts) files with ES6+ syntax and then compile & upload your files to Drive with clasp push --watch.
Alternatively, you can use Webpack in your local setup as detailed in this answer.

My guess is AngluarJS is since it was made by a google developer.

Related

How to Get Proper Formatting with the V8 Google Apps Script IDE

Edit: Fixed!
The Google Apps Script team rolled this out for our team earlier this week (week of January 10th).
Original Post
I'm a frequent GAS user, and I've noticed that, since the upgrade to the V8 runtime, formatting in the GAS IDE is awful. I've seen a somewhat similar question here, but my problem is that the GAS IDE is terrible at formatting ES6 Javascript.
Expected Behavior
variables defined with const or let appear similarly to variables defined with var
the omission of a semicolon will not completely break the indention / formatting of a script
destructured variables will be recognized as variables by the IDE
template literals will be recognized by the IDE
Current Behavior
The IDE basically doesn't recognize any of my JavaScript ES6 syntax. Here's an example:
/** Comments about some function.
* #dev Why does this look like garbage!?
*/
function foo() {
...
}
In the above example, it's impossible to get the IDE to properly indent the function. Instead, each line of code is indented to the same extent by default.
Has anyone figured out how to use ES6 syntax, omit semicolons, etc. and gotten the browser-based GAS IDE to format properly?
Thanks!
You might try to use a web browser extension that allow you to set custom CSS styles but the effort required might not be worthy because the new Google Apps Script is being rolled out.
According to the last announcement update the rollout should finish during January 2021
Reference
Use the new Apps Script Integrated Development Environment (IDE) Script Editor
Related
Get ready to up your Apps Script!
Workaround
If there are any missing features or behaviours that you don't like on the Apps Script IDE you can:
Update to the newer version of the IDE with more features described here
Use clasp which allows you to develop and manage Apps Script projects from your terminal rather than the Apps Script editor therefore being able to use the IDE of your choice with the features you like.
If there is a specific missing feature you would like the Apps Script editor to have you can report a feature request

Load jQuery in node.js CLI [duplicate]

This question already has answers here:
Can I use jQuery with Node.js?
(21 answers)
Closed 6 years ago.
I'm an R developer by day and I'm trying to learn to do stuff with Javascript at night. I'm very used to the REPL type environment where I can run code in the IDE where I'm working. The code I'm writing is for a web application, but I'm still in the learning stage with Javascript so I want to do exploration, practice, etc. and I'd like to do it in a REPL environment so I can try something, fail, try something else, etc.
I have installed node.js and configured Sublime Text to "build" my Javascript files via node in the CLI. However, I'd like to try using some things from jQuery. Is there a way for me to load jQuery into the node.js execution environment so my standalone script can use the necessary features?
To be clear, I'm not talking about use node.js on a server, as a webserver, any of that. I'm just using node.js as an execution environment on my PC to execute vanilla and, hopefully, slightly french bean vanilla code.
I've read that you can't source in other Javascript files but obviously a web browser loads in code from multiple sources and co-mingles them so it seems like I should be able to do something similar when executing on my local machine.
If you just want to try jQuery in a REPL environment, you can do that from the dev tool from your browser (major browsers has it called 'console' under F12 usually), no need for nodejs here, JS engines are implemented in browsers.
But if you want to use the same core functionality and syntax of jQuery, you might want to try cheerio package https://cheerio.js.org it's a:
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.

Array.filter function in serverside Javascript

I would like to filter an array in my XPage with serverside Javascript. Unfortunately I get the following error:
Error calling method 'filter(Function)' on an object of type 'Array [JavaScript Object]'
I have an Array of Strings like ["elem1","elem2","elem3"]
I call the function like this:
list.filter(function(){
});
Is there any reason why this error happens? Does this function even exist in ssjs?
This question is not duplicate since it is not clear that Xpages/Lotus Notes runs Rhino in background.
It sounds like whatever server-side JavaScript environment you're using doesn't support ES5 features (that's features from the 5th edition specification from December 2009).
You can use a polyfill for that and other things that were added to Array, see MDN, but beware: If ES5 features aren't supported, it's impossible to add things to Array.prototype without making them enumerable, meaning any code (mis)using for-in to loop through arrays will be affected.
There is Rhino behind XPages. And this SO topic
No Array.filter() in Rhino? says, it is out of date.
Edit:
No, it is not. Years ago I read somewhere about it. Now it seems it was not true. According to comment by Dan Sickles (quoting Philippe Riand?) here:
It runs on the server jvm and uses javascript as the application
language. For licensing reasons, IBM wrote their own jvm javascript
engine instead of using Rhino. With Rhino shipping in java 6, they
should be able to ship it in Designer 8.5 (or later). The licensing
problems may have been around the extensions like #Formulas and type
declarations. Classes, modules/namespaces and type declarations are
coming in javascript 2 and even google is helping to get that
implemented in Rhino. I'd hate to see a non-standard, javascript
engine underlying the coolest web development technology in Domino.
Speaking of Rhino, the "most important new feature that is not as
certain to be in 8.5 as XPages" uses Rhino and other jvm scripting
languages on the client. If this makes it into the product, two years
from now most new Notes applications will be written in neither
Lotusscript nor Java. I'll leave it at that.
In fact, there are few topics how to use Rhino in XPages, so with newest Rhino version your code would work. Anyway, my advice is to use Java calls.

Where can I find javascript native functions source code? [duplicate]

This question already has an answer here:
How can I see the source of built-in JavaScript functions? [closed]
(1 answer)
Closed 6 years ago.
where can I find the source code of native js functions, for example I want to look at eval() function
Both Chrome and Firefox are open source and you can look at the implementation of any part of the javascript engine in the source code for those products. Other browsers have their own implementation (like IE) that is not available to the public to look at.
The Chrome v8 javascript engine code is here: https://github.com/v8/v8
The Firefox SpiderMonkey engine code is here:
https://searchfox.org/mozilla-central/source/js/src
Warning, if you aren't already familiar with those products and their tools, it may take while to get familiar enough to find what you're looking for.
These links may change over time, but can easily be found with Google searches if they move.
Javascript is a script language that is implemented within a Browser's code-base. This means that there may be different implementations of the script language, with different levels of quality, and possibly different intepretations of what is required. Hence the head-against-wall frustrations of many a web-developer when dealing with different web-browsers.
It is possible for you to examine a browser's implementation of Javascript if the browser is an Open Source version, eg: Chrome, Firefox, as given in other answers listed.
In the JavaScript engine's source code.

Is Javascript only available for web browsers?

I would like to know about Javascript. Is Javascript available only for web browsers? Because I used some Javascript code for Firefox Plugin development and Thunderbird.
Help me to find out more about this: where can I use JavaScript other than web browsers, and how?
There's node.js which includes a full webserver and runs on Google's V8
No! Have a look at Google's V8
Google Javascript. Click first link (Wikipedia). Click "uses outside webpages".
http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages
There are a number of server-side (or otherwise non-browser) implementations of Javascript, including Node.js, which currently has a lot of momentum behind it, as well as the now-defunct Jaxer, which provided a server-side DOM implementation based on Mozilla Gecko. There are also efforts to bring DOM type functionality to Node.js, primarily from Yahoo.
With Rhino, you can embed Javascript in Java applications.
No, there are definitely other implementations. For instance, JScript.Net is included with the .NET framework.
MS-Windows can execute .js files (from the command prompt).
Since you do not have the browser context, you cannot use any calls to the browser (alert, for example, does not work).
Look for "Windows Scripting Host".
WSH supports scripts written in
Microsoft Visual Basic Scripting
Edition (VBScript) or JavaScript.
There are several implementations of stand-alone Javascript
JSLibs (http://code.google.com/p/jslibs/) is general purpose
jsdb (http://www.jsdb.org/) is more database oriented
Many text editors (including the one I use, ActiveState's Komodo Edit) expose their APIs and let you write macros in Javascript.
Using Adobe AIR you can write almost platform-independent Desktop Applications using JavaScript
PDF files can also contain JavaScript code. See first entry in google on this subject and also Adobe JavaScript virus.
Javascript can be easily embedded in applications written in other programming languages.
For Java there is as already mentioned Rhino, for C++ you can use for example Flusspferd. Here are some tutorials/examples.
Qt has the QtScript module. From Qt 4.7 it uses JavaScriptCore (the Webkit JavaScript engine).
In short, No.
Actually, Javascript and other Web technologies are used these days to create native mobile and desktop applications. (see Titanium Appcelerator and PhoneGap)
If you are familiar with the KDE project you can craft Plasma widgets using JavaScript, see Creating plasmoids with JavaScript
In Qt framework there is a QtScript module for JavaScript (ECMAScript) application scripting to provide much of the application’s functionality.
Also the new technology that is soon to be released in Qt 4.7 is Qt Quick, aka the Qt UI Creation Kit, which allows application developers to declaratively define their user interfaces in QML, for more information go here and an example here
QML is an extension to JavaScript,
that provides a mechanism to
declaratively build an object tree of
QML elements. QML improves the
integration between JavaScript and
Qt's existing QObject based type
system, adds support for automatic
property bindings and provides network
transparency at the language level.
And let's not forget Javascript is used as an embedded scripting language in various applications OpenOffice.org, Google Desktop Widgets, and many others, see Wikipedia's article here
On the server-side Javascript enables back-end access to databases, file systems, etc (see Node.js, Google V8, SpiderMonkey and others here)
Some document databases, such as CouchDB and MongoDB, use JavaScript to interact with the database.

Categories