Elsewhere in the code we test 

if (window.flags && window.flags.state)
// do the new thing.

This has the advantage of having the new code at the beginning of the block and the test is easier to read.

In the Python world we have a coding standard that encourages testing for the positive case.  Would be nice to see that here (and below.)