{"record":{"id":"c695ec420e3d5d7b","repo":"nwjs/nw.js","slug":"click-must-be-a-valid-function-c695ec","errorCode":null,"errorMessage":"'click' must be a valid Function","messagePattern":"'click' must be a valid Function","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_menuitem.js","lineNumber":67,"sourceCode":"      option.iconIsTemplate = Boolean(option.iconIsTemplate);\n    else\n      option.iconIsTemplate = true;\n\n    if (option.hasOwnProperty('tooltip'))\n      option.tooltip = String(option.tooltip);\n\n    if (option.hasOwnProperty('enabled'))\n      option.enabled = Boolean(option.enabled);\n\n    if (option.hasOwnProperty('submenu')) {\n      // Transfer only object id\n      privates(this).submenu = option.submenu;\n      option.submenu = option.submenu.id;\n    }\n\n    if (option.hasOwnProperty('click')) {\n      if (typeof option.click != 'function')\n        throw new TypeError(\"'click' must be a valid Function\");\n      else\n        this.click = option.click;\n    }\n  } else if (option.type == 'separator') {\n    option = {\n      type: 'separator'\n    };\n  }\n\n  var id = option.id || nw.Obj.allocateId();\n  this.id = id;\n  privates(this).option = option;\n\n  menuItems.objs[id] = this;\n  // All properties must be set after initialization.\n  if (!option.hasOwnProperty('icon'))\n    option.shadowIcon = '';\n  if (!option.hasOwnProperty('tooltip'))","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_menuitem.js#L49-L85","documentation":"Thrown by the nw.MenuItem constructor when 'click' is present in options but is not a function. The click handler is invoked on item activation, so it must be callable.","triggerScenarios":"Calling `new nw.MenuItem({ label: 'x', click: 'doClick' })` or `click: undefined` after a failed lookup.","commonSituations":"Passing a handler name string from config; the method reference did not bind correctly.","solutions":["Pass a function reference: `new nw.MenuItem({ label: 'x', click: doClick })`.","Bind if needed: `click: obj.doClick.bind(obj)`.","Omit 'click' and use item.on('click', fn) after construction."],"exampleFix":"// before\nnew nw.MenuItem({ label: 'Quit', click: 'onQuit' });\n// after\nnew nw.MenuItem({ label: 'Quit', click: onQuit });","handlingStrategy":"type-guard","validationCode":"if (option.hasOwnProperty('click') && typeof option.click !== 'function') delete option.click;","typeGuard":"function isClickFn(v) { return typeof v === 'function'; }","tryCatchPattern":"try { new nw.MenuItem(opt); } catch (e) { if (/click/.test(e.message)) { delete opt.click; new nw.MenuItem(opt); } else throw e; }","preventionTips":["Pass function references, not names.","Bind methods before assigning to click."],"tags":["menuitem","constructor","type-check","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}