ssssssss-team/spider-flow · error · TypeError
" + g + " is not a function
Error message
" + g + " is not a function
What it means
The same Array.prototype.forEach polyfill in formSelects-v4.js validates its first argument. If the callback `g` is not a function it throws TypeError(g + ' is not a function'), mirroring the ES5 specification. The odd message text with escaped quotes is an artifact of how the error was captured/escaped.
Solutions
- Ensure the first argument to forEach is a function; check the callback variable is defined and spelled correctly.
- Guard: `if (typeof cb === 'function') arr.forEach(cb)`.
- Fix argument order if values were swapped at the call site.
Example fix
// before
list.forEach(callbackName); // callbackName is undefined
// after
if (typeof callbackName === 'function') { list.forEach(callbackName); } Defensive patterns
Strategy: validation
Validate before calling
if (typeof callback !== 'function') { throw new TypeError('forEach callback must be a function, got: ' + callback); } items.forEach(callback); Type guard
function isFunction(v) { return typeof v === 'function'; } Try / catch
try {
items.forEach(callback);
} catch (e) {
if (e instanceof TypeError && /is not a function/.test(e.message)) { callback = defaultCallback; items.forEach(callback); }
else throw e;
} Prevention
- Verify the callback reference is defined at the call site (typos rename risk).
- Check argument order when wrapping forEach-like calls.
- Use linters (no-undef, no-unused-vars) to catch undefined callback references.
When it happens
Trigger: Passing a non-function (undefined, null, string, object) as the first argument to forEach, typically because the callback variable is undefined due to a typo, failed lookup, or wrong argument order.
Common situations: Calling `arr.forEach(arr[i])` style mistakes, callbacks returned from optional APIs that came back undefined, refactors that renamed the callback function but not all call sites, in environments relying on the polyfill (old IE).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of ssssssss-team/spider-flow@c799cca99c (2026-09-08).
Data as JSON: /api/errors/3f3843d75b102d0f.
Report an issue: GitHub.
Appendix: source
Thrown at spider-flow-web/src/main/resources/static/js/layui/extends/formSelects-v4.js:208
c,
e = Object(this),
f = e.length >>> 0;if (h) {
b = h;
}a = new Array(f);c = 0;while (c < f) {
var d, g;if (c in e) {
d = e[c];g = i.call(b, d, c, e);a[c] = g;
}c++;
}return a;
};
};
//拓展Array foreach方法
if (!Array.prototype.forEach) {
Array.prototype.forEach = function forEach(g, b) {
var d, c;if (this == null) {
throw new TypeError("this is null or not defined");
}var f = Object(this);var a = f.length >>> 0;if (typeof g !== "function") {
throw new TypeError(g + " is not a function");
}if (arguments.length > 1) {
d = b;
}c = 0;while (c < a) {
var e;if (c in f) {
e = f[c];g.call(d, e, c, f);
}c++;
}
};
};
//拓展Array filter方法
if (!Array.prototype.filter) {
Array.prototype.filter = function (b) {
if (this === void 0 || this === null) {
throw new TypeError();
}var f = Object(this);var a = f.length >>> 0;if (typeof b !== "function") {
throw new TypeError();
}var e = [];var d = arguments[1];for (var c = 0; c < a; c++) {View on GitHub (pinned to c799cca99c)