为变量内的函数设置布尔值

时间:2017-06-04 14:21:36

标签: javascript function variables boolean

function newcountry(continent,country)
  local object = {}
  object.continent = continent
  object.country = country

  local list = {}

  for i in pairs( object ) do
   if object.continent == "Europe" then
     table.insert(list, object.country)
     print(object.country)

  end
end

  return object
end


a = newcountry("Africa","Algeria")
b = newcountry("Europe","England")
c = newcountry("Europe","France")
d = newcountry("Europe","Spain")
e = newcountry("Asia","China")

我的问题是如何做这样的事情:// openMNav.isDropDown = false; var openMNav = function () { if (!this.isDropDown) { this.isDropDown = true; console.log(1); } else { this.isDropDown = false; console.log(0); } 。 我想设置openMNav - >函数外的isDropDown为false

1 个答案:

答案 0 :(得分:2)

你的意思是设置函数本身,你应该在函数中使用openMNav而不是这个。

function openMNav () {

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

openMNav();
openMNav();