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.

Bug 225780 - Parameter marked as unused when used in return statement function
Summary: Parameter marked as unused when used in return statement function
Status: VERIFIED INVALID
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.3
Hardware: PC Linux
: P4 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-06 08:42 UTC by Vladimir Riha
Modified: 2014-02-04 12:37 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Riha 2013-02-06 08:42:21 UTC
Please try following:

window.requestAnimFrame = (function(callback) {
    return window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            function(callback) {
                window.setTimeout(callback, 1000 / 60);
            };
})();


"callback" is marked as unused



Product Version: NetBeans IDE 7.3 RC2 (Build 201302050851)
Java: 1.7.0_13; Java HotSpot(TM) Client VM 23.7-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_13-b20
System: Linux version 3.2.0-35-generic-pae running on i386; UTF-8; en_US (nb)
Comment 1 Petr Pisl 2013-02-11 13:36:56 UTC
The first parameter "callback" in this case is really unused. The return statement contains a usage of "callback" parameter that is a parameter of the function wrapping the usage.
Comment 2 Vladimir Riha 2013-02-11 14:29:17 UTC
I'm not sure, I simplified it to this:


var a = (function(callback) {
    return false ||
            function(callback) {
                alert(callback);
            };
})(); 

a(2);


And alert window contains 2. I think that because on the last line the function is called immediately, the first parameter is passed to the second one.
Comment 3 Petr Pisl 2013-02-12 09:30:44 UTC
Thanks, I get it:). Unfortunately I don't have doubt how to solve this. So lets keep it as reminder.
Comment 4 Eccenux 2014-02-04 12:19:57 UTC
The correct code would be:

```
window.requestAnimFrame = (function() {
    return window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            function(callback) {
                window.setTimeout(callback, 1000 / 60);
            };
})();
```


Note that this will also give "2":

```
var a = (function() {
    return false ||
            function(callback) {
                alert(callback);
            };
})(); 

a(2);
```

This would also work the same:
```
var a = function(callback) {
               alert(callback);
        };
a(2);
```

Note that you simply define an anonymous function and "save" it to a variable `a` (in first case you return the function as a value). And callback in original code is really unused (as it is shadowed by function argument).

This will give you "outside":
```
var a = (function(callback) {
    callback = "inside"
    return false ||
            function(callback) {
                console.log(callback);
            };
})(); 

a("outside");
```

This will give you `undefined` (because you haven't passed any parameters) and "outside":
```
var a = (function(callback) {
    return false ||
            function(callbackInside) {
                console.log(callback);
                console.log(callbackInside);
            };
})(); 

a("outside");
```

This will give you "calling anon" and "outside":
```
var a = (function(callback) {
    return false ||
            function(callbackInside) {
                console.log(callback);
                console.log(callbackInside);
            };
})("calling anon"); 

a("outside");
```
Comment 5 Vladimir Riha 2014-02-04 12:37:08 UTC
You're right of course, the "proof" in comment #2 does not really prove anything :). Thank you for noticing that.