{"record":{"id":"d479cbd6b4f2bad6","repo":"alvarotrigo/fullPage.js","slug":"this-is-null-or-not-defined","errorCode":null,"errorMessage":"\"this\" is null or not defined","messagePattern":"\"this\" is null or not defined","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/js/polyfills/array.find.js","lineNumber":7,"sourceCode":"// https://tc39.github.io/ecma262/#sec-array.prototype.find\nif (!Array.prototype.find) {\n    Object.defineProperty(Array.prototype, 'find', {\n        value: function(predicate) {\n            // 1. Let O be ? ToObject(this value).\n            if (this == null) {\n                throw new TypeError('\"this\" is null or not defined');\n            }\n\n            var o = Object(this);\n\n            // 2. Let len be ? ToLength(? Get(O, \"length\")).\n            var len = o.length >>> 0;\n\n            // 3. If IsCallable(predicate) is false, throw a TypeError exception.\n            if (typeof predicate !== 'function') {\n                throw new TypeError('predicate must be a function');\n            }\n\n            // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.\n            var thisArg = arguments[1];\n\n            // 5. Let k be 0.\n            var k = 0;\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/alvarotrigo/fullPage.js/blob/49f15effa7b195def295a36f872c28153cf9fb00/src/js/polyfills/array.find.js#L1-L25","documentation":"Thrown by the Array.prototype.find polyfill (src/js/polyfills/array.find.js:7) during spec step 1, which coerces the receiver to an object via ToObject(this). When the method is invoked with a this value of null or undefined, ToObject cannot coerce it and the polyfill surfaces the failure as this explicit TypeError. The native ES6 implementation throws the identical error, so this only runs on browsers lacking Array.prototype.find.","triggerScenarios":"Invoking the find polyfill on a null/undefined receiver: Array.prototype.find.call(null, fn) or .call(undefined, fn); detaching the method reference so this is undefined in non-strict scope (const f = arr.find; f(fn)); or calling a stored/aliased copy of find without rebinding it to an array.","commonSituations":"Saving a method reference in a variable, callback, or decorator and invoking it bare so this is lost; spread/destructure bugs that resolve the array to null/undefined; old browsers (IE11 and earlier) where the polyfill is active and code assumed a real array was present.","solutions":["Ensure find is called as a member of an actual array: arr.find(predicate).","If invoking indirectly, bind the receiver: const f = arr.find.bind(arr); f(predicate) or Array.prototype.find.call(arr, predicate).","If the array may be missing, guard the call site with optional chaining or a null check: (arr && Array.isArray(arr)) ? arr.find(predicate) : undefined.","Confirm the polyfill is even needed: if Array.prototype.find exists natively, a null receiver still throws natively, so the root cause is the receiver, not the polyfill."],"exampleFix":"// before\nconst find = list.find;\nfind(isActive); // \"this\" is null or not defined\n\n// after\nlist.find(isActive);\n// or, if indirect call is required:\nconst find = list.find.bind(list);\nfind(isActive);","handlingStrategy":"type-guard","validationCode":"function safeFind(arr, predicate, thisArg) {\n  if (arr == null || !Array.isArray(arr)) {\n    return undefined;\n  }\n  if (typeof predicate !== 'function') {\n    throw new TypeError('predicate must be a function');\n  }\n  return Array.prototype.find.call(arr, predicate, thisArg);\n}","typeGuard":"function isArrayLike(value) {\n  return value != null && typeof value !== 'boolean' && typeof value !== 'number' && typeof value[Symbol.iterator] === 'function' || (typeof value === 'object' && Number.isFinite(Number(value.length)));\n}","tryCatchPattern":null,"preventionTips":["Never store a method reference without binding it: use arr.find.bind(arr) or arrow wrappers.","When calling via .call/.apply, always pass the array explicitly as the first argument.","Validate the receiver is a real array with Array.isArray before invoking find."],"tags":["polyfill","array","this-binding","typeerror","es2015"],"backgroundTag":null,"analyzedSha":"49f15effa7b195def295a36f872c28153cf9fb00","analyzedAt":"2026-08-13T04:33:34.972Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}