This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 153323 [details] Unused-hint-for-functions.png (See attached screenshot for details) For better debug experience in Chrome I always give explicit names to ALL functions in my JS library. When function is immediately assigned to a variable or property, its name ... According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions -> Function constructor vs. function declaration vs. function expression "The function name can be used only within the function's body. Attempting to use it outside the function's body results in an error (or undefined if the function name was previously declared via a var statement)" ... CANNOT be used outside of function and therefor 'unused' hint is actually unavoidable according to JS grammar. Typical in such case function is supposed to be anonymous, but it leads to weird call stack in debugger (see screenshot). So I think there should be some special handling for that case. I see two choice: 1. Just do not generate 'unused' hint for that particular case (least amount of changes, noone really cares about 'unused' in that case) 2. Create an individual option/setting for that case so that users like me could disable only that case while keeping 'unused' hint for other cases. Special cases are: 1. var fn = function FnName(); 2. var obj = {fn: function FnName()}; 3. do_something(function MyCallback() {}); Below is a longer test script where I expect to see no 'unused' hints. BTW: currently there is inconsistent behavior - 'unused' hint is not generated for code in 'global' scope, but is generated for 'local function' scope. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* global SomeLib */ var _extend = SomeLib.extend; var MyLib = new function MyLib() { this.Cls = Cls; var _fn = function _Cls_fn(arg) { console.info(arg); console.info(function My_Callback_Function() { }); debugger; }; function Cls() { } _extend(Cls.prototype, { fn1: function Cls_fn1(arg) { _fn(arg); }, fn2: function (arg) { this.fn1(arg); }, fn3: function (arg) { this.fn2(arg); }, fn4: function Cls_fn4(arg) { this.fn3(arg); } }); }; var _fn = function _fn(arg) { console.info(arg); debugger; }; function Cls() { } _extend(Cls.prototype, { fn1: function Cls_fn1(arg) { _fn(arg); }, fn2: function (arg) { this.fn1(arg); }, fn3: function (arg) { this.fn2(arg); }, fn4: function Cls_fn4(arg) { this.fn3(arg); } }); (new Cls()).fn4("arg"); (new MyLib.Cls()).fn4("arg");
Reproducible Product Version: NetBeans IDE Dev (Build 201504170001) Java: 1.8.0_40; Java HotSpot(TM) Client VM 25.40-b25 Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b25 System: Linux version 3.13.0-35-generic running on i386; UTF-8; en_US (nb)
I have played with this. The first problem here is that the parser doesn't mark these anonymous functions as anonymous. I know how to fix it if the anonymous function is used in var definition. I need to find out a solution for the object literal case. But this is just start. Then I have to change the way how such functions are handled so far. Like anonymous functions are not displayed in navigator, are not colored in semantic analyzer etc. I will create separate issue for different cases that has to be handled.