Karl B.
Karl B.

Reputation: 263

Set boolean for a function inside a variable

//     openMNav.isDropDown = false;
       var openMNav = function () {                         
              if (!this.isDropDown) {
              this.isDropDown = true;
              console.log(1);
            } else {    
              this.isDropDown = false;
              console.log(0);                          
        }

My question is how to do something like this: var openMNav.isDropDown = false;. I want to set openMNav -> isDropDown outside the function to false

Upvotes: 0

Views: 225

Answers (1)

Kyle
Kyle

Reputation: 86

You mean to set on the function itself, you should just use openMNav in the function not this.

function openMNav () {

    if (!openMNav.isDropDown) {
        console.log('do open');
        openMNav.isDropDown = true;
    }
    else {
        console.log('already opened');
        openMNav.isDropDown = false;
    }
}

openMNav();
openMNav();

Upvotes: 2

Related Questions