-3

I'm having a piece of code very simple. It checks two parameters. If first parameter is false it change the popup icon in the chrome extension, if it's true and previously was false, then it change the icon backs and if no parameters is passed it returns the current values.

The problem is that either way, both the variable and the first parameter that is being passed as boolean, is interpreted as string and that produce unexpected results. Here's my code:

var status = true;
var reason;
function isReady(statusT, reasonT) {
    "use strict";
    if (statusT === false) {
        chrome.browserAction.setIcon({
            path : "img/blue-sharingan.png"
        });
        status = statusT;
        if (reason !== undefined) {
            reason = reasonT;
            return;
        }
        return;
    }
    if (statusT === true && status === false) {
        chrome.browserAction.setIcon({
            path : "img/icon-32.png"
        });
        status = statusT;
        reason = null;
        return;
    }
    if (statusT === undefined && reasonT === undefined) {
        return {
            'status' : status,
            'reason' : reason
        };
    }
}

I've read https://stackoverflow.com/a/653934/792066 and I still don't figure out what could be wrong.

Braiam
  • 4,345
  • 11
  • 47
  • 69
  • @Braiam Yeah, this was the best of the available questions for the canonical duplicate, but I found the answer by Oriol superior to the others. Maybe I should instead have requested a merge. – Bergi Nov 30 '16 at 15:15
  • 1
    @Braiam I was mostly thinking of [this one](https://stackoverflow.com/q/3082475/1048572), which you identified today? If the title bugs you, that's easily fixed with an edit. – Bergi May 18 '20 at 13:13

0 Answers0