5

The title says it all, but let's say I have a hasAccess() function returning true or false

I use it in a ExtJS 4 toolbar button config like this :

{
  id:      'btnEditMyStuff',
  ref:     'edit_my_stuff',
  xtype:   'button',
  text:    'Edit',
  hidden:  !( MyUser.hasAccessTo('EditMystuff') )            
}

Even if this expression gets correctly evaluated to false when tested in Firebug, my button won't show up.

But with this :

{
  id:      'btnEditMyStuff',
  ref:     'edit_my_stuff',
  xtype:   'button',
  text:    'Edit',
  hidden:  ( MyUser.hasAccessTo('EditMystuff') == false )            
}

the button is correctly displayed.

The question is : what is the difference ?

What mysterious comparison operators/function evaluation precedence am I overlooking here ?

I want to go to bed less dumb than yesterday. Thanks in advance.

EDIT :

 hidden:  !( MyUser.hasAccessTo('EditMystuff') )  // does not work
 hidden:  (!MyUser.hasAccessTo('EditMystuff') )   // works    

but still I crave to fully understand.

4

1 回答 1

1

好吧,你大多是对的

!(true) is false
!(false) is true

 true == false is false
 false == false is true

因此,如果输入只是真假,但如果输入是空数组,那么您可以

 ![] is false

  []==false is true
于 2013-05-28T14:50:02.323 回答