Copy link to clipboard
Copied
So, a script I was developing was working fine yesterday, but today, it seems like my Array built-in object is broken. I tried restarting After Effects to reset the environment, but it's still broken. So far, I've identified that "map", "includes", and "split" are broken, though "shift" is fine. I don't have any custom startup scripts.
I've attached a simple .txt file that demonstrates this error for me, though I'm guessing it would work normally. Just rename it to .jsx and run it yourself.
OS: MacOS Big Sur v11.4
AE: v18.4.0 build 41
Copy link to clipboard
Copied
EDIT:
Whoops, "split" is a string function, it won't work anyway, ahahah.
Still, "map" and "includes" are both broken for me.
Copy link to clipboard
Copied
In general, you cannot expect Ae scripting to support all features of modern JavaScript.
After Effects scripting is using ExtendScript and ExtendScript implements the JavaScript language according to the ECMA-262 specification. This is a very old variant of JavaScript and it does not include features like Array.map, yet.
Copy link to clipboard
Copied
The worst difference I found so far is actually this one:
true || true && false
evaluates to "false" in After Effects ExtendScript, but to "true" in modern JavaScript.
Because After Effects reads it as
(true || true) && false
whereas modern JavaScript reads it as
true || (true && false)
So when writing logic statements, make sure to always set parenthesis to avoid trouble. And don't use minifiers like uglify.js which remove these parenthesis.
Copy link to clipboard
Copied
same issue here in 2024.
resetting preferences did not solve it but
Edit -> Purge -> All Memory And Disk Cache ... did resolve it
in case this does not resolve it, you can manually write the array prototype functions in case they are missing:
// Polyfill for .map() if it doesn't exist
if (!Array.prototype.map) {
Array.prototype.map = function(callback, thisArg) {
var T, A, k;
if (this == null) {
throw new TypeError(" this is null or not defined");
}
var O = Object(this);
var len = O.length >>> 0;
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
if (arguments.length > 1) {
T = thisArg;
}
A = new Array(len);
k = 0;
while (k < len) {
var kValue, mappedValue;
if (k in O) {
kValue = O[k];
mappedValue = callback.call(T, kValue, k, O);
A[k] = mappedValue;
}
k++;
}
return A;
};
}
// Polyfill for .includes() if it doesn't exist
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement, fromIndex) {
var O = Object(this);
var len = parseInt(O.length, 10) || 0;
if (len === 0) {
return false;
}
var n = parseInt(fromIndex, 10) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {
k = 0;
}
}
while (k < len) {
if (O[k] === searchElement) {
return true;
}
k++;
}
return false;
};
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now