Skip to main content
mickyhulse
Known Participant
June 20, 2019
Answered

What version of JavaScript supported?

Hello,

I was just curious what version of JS does ESTK support for Adobe Illustrator?

I am noticing that “const” works, but “let” does not.

Is there a list somewhere of supported language features?

Thanks!

This topic is closed to new replies. Start a new post to keep the conversation going.
Inventsable
InventsableCorrect answer
Legend
March 2, 2023

Likely a copy/paste error on my part, apologies. Check here to reference

22 replies

Lumenn
Inspiring
July 2, 2019

Thanks !

Gonna check it out

Translate
Inventsable
Legend
June 26, 2019

Was told by Remco Janssen that this already exists somewhere, but regardless here's filter, map, find, and forEach:

  // Support for filter()

  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

  //

  Array.prototype.filter = function(callback) {

   var filtered = [];

   for (var i = 0; i < this.length; i++)

     if (callback(this, i, this)) filtered.push(this);

   return filtered;

  };


  // Support for find()

  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

  //

  Array.prototype.find = function(callback) {

   var filtered = [];

   for (var i = 0; i < this.length; i++)

     if (callback(this, i, this)) return this;

  };


  // Support for map()

  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

  //

  Array.prototype.map = function(callback) {

   var mappedParam = [];

   for (var i = 0; i < this.length; i++)

     mappedParam.push(callback(this, i, this));

   return mappedParam;

  };


  // Support for forEach()

  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

  //

  Array.prototype.forEach = function(callback) {

    for (var i = 0; i < this.length; i++) callback(this, i, this);

  };

Translate
schroef
Inspiring
March 2, 2023

@Inventsable 

Wondering why these prototypes dont seem to work properly with cc 2018. I tried that Array prototype and it returns the complete list added 4 times with this example. Unless i dont change a small part in the function, it wont work correct

 

// Inventsable
// https://community.adobe.com/t5/illustrator-discussions/what-version-of-javascript-supported/m-p/10488213#M136748
Array.prototype.forEach = function(callback) {
    for (var i = 0; i < this.length; i++) callback(this[i], i, this);
};


var sum = 0;
var numbers = [65, 44, 12, 4];
numbers.forEach(myFunction);
function myFunction(item) {
  sum += item;
}
alert(sum)

Noticed that in the callback(this,i, this) i made a change to callback(this[i], i, this). Otherwise it return the complete array each time its called?! 

Translate
Inventsable
InventsableCorrect answer
Legend
March 2, 2023

Likely a copy/paste error on my part, apologies. Check here to reference

Translate
Ten A
Community Expert
Community Expert
June 20, 2019

ExtendScript based ECMA Edition 3 and not support "let" and "const" is better not to use it.

You can refer below.

Use of 'const' in ExtendScript

Translate
mickyhulse
Known Participant
June 20, 2019

Awesome, thanks Ten, I really appreciate the help!

Also, thanks for the linkage ... That's very helpful.

Looks like I'll stick to es3 and be happy with it.

Thanks again!

Translate
Silly-V
Legend
June 20, 2019

Hey there! It's been a while, look who's back!

Also, ExtendScript has 'extras' such as - it supports triple quotes which act almost like template strings, except no normal syntax highlighter for javascript would recognize them, as well as xml inside of javascript!

Translate