Notice "Identifier ['=' Expression] ';'". Semantically, this is neither an assignment nor a variable declaration, it simply adds a field to the class. Semantically it's equivalent to "Test.mX = 0;" (which further degrades to "Test["mX"] = 0"), an indexed assignment.

Furthermore, when you're implicitly accessing mX in the function, it doesn't even necessarily mean "the mX defined in this class". It means "the mX that's found in 'this' or in the global namespace." For that matter, right after your class declaration, you could write "removeKey(fieldsOf(Test), "mX");" -- suddenly, there's no more mX field in Test, and the reference to mX in foo() will probably refer to a global instead.

The same ideas apply to tables as well, with their named fields (i.e. "{x = 5}").