'use strict' mode unreliable?

● ARCHIVED · READ-ONLY
Started by SilverDash 24 posts Page 2 of 2 View original ↗
  1. SilverDash said:
    Weird, I tried strict-mode again and now it works properly (same pc). Maybe one of the RPG Maker patches fixed it. I now get errors when undefined variables are used.
    I have never had this issue, maybe you did it wrong?
  2. <deleted>. I can't make a serious response to it other than that maybe this PC changed somehow something somewhere in the meantime. Same code, different results... SAME CODE...... Different results...
  3. I'm with DarknessFalls on this one and i strongly suspect that strict mode didn't work for you, because you are not wrapping your code in an anonymous function. Strict mode is enabled or disabled per function and since the base scripts don't use it, your plugin is inheriting their "strict mode disabled" state.


    The fact that it works in some browsers is probably implementation specific, since you aren't intended to use strict mode outside a function, anyway. So, if you follow the best practice, wrapping your code in an anonymous function and placing "use strict"; as the (important) first statement inside that function, it will work.
  4. yes I made a mistake declaring it outside of the anonymous function at the start. Once I learned that strict-mode had a scope, I changed it. But when I create an empty project, clean plugin. With or without an anonymous function, and I put code like this in it (strict-mode also within the anonymous function):

    "use strict";myFunction();function myFunction() { y = 3.14; // This does or does not cause an error depending on platform(=Firefox, Chrome, Windows)/client...}And it gave me different results depending on what platform/pc I was using for the exact same code.

    Now if I would have done it wrong, it should ALWAYS 'bug' OR never bug. But it depends on platform/client. And wrapping or not wrapping the plugin with an anonymous function (which I both tried) should not make a difference. And if it does, either JS or RM is bugged.