diff --git a/src/util/cast.js b/src/util/cast.js index 8102f04af..604100ec8 100644 --- a/src/util/cast.js +++ b/src/util/cast.js @@ -1,5 +1,13 @@ const Color = require('../util/color'); +/** + * Store and possibly polyfill Number.isNaN. Number.isNaN can save time over + * self.isNaN by not coercing its input. We need to polyfill it to support + * Internet Explorer. + * @const + */ +const _NumberIsNaN = Number.isNaN || isNaN; + /** * @fileoverview * Utilities for casting and comparing Scratch data-types. @@ -25,14 +33,14 @@ class Cast { if (typeof value === 'number') { // Scratch treats NaN as 0, when needed as a number. // E.g., 0 + NaN -> 0. - if (isNaN(value)) { + if (_NumberIsNaN(value)) { return 0; } return value; } const n = Number(value); - if (isNaN(n)) { + if (_NumberIsNaN(n)) { // Scratch treats NaN as 0, when needed as a number. // E.g., 0 + NaN -> 0. return 0;