Reply To: Math.sign doesn't exist!!!

#14323337

Yes, Math.sign does not exist in ExtendScript.

Math.sign and other such functions, for example String.startsWith, Array.indexOf have been added to newer versions of ECMAScript, and are available in web browsers, but not in ExtendScript.

I tend to use polyfills for such cases.

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign

if (!Math.sign) {
Math.sign = function(x) {
// If x is NaN, the result is NaN.
// If x is -0, the result is -0.
// If x is +0, the result is +0.
// If x is negative and not -0, the result is -1.
// If x is positive and not +0, the result is +1.
return ((x > 0) – (x < 0)) || +x;
};
}

Add this polyfill, and your code should work fine.

Thanks,
MT

This article was last modified on January 4, 2020

Comments (0)

Loading comments...