Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.
Original Source
- Original title: A small example of why to "use strict" mode.
- Original author: Joy Diamond
- Original date: December 3, 2017
- Source thread: https://forums.rpgmakerweb.com/threads/a-small-example-of-why-to-use-strict-mode.88036/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Learning Javascript
Summary
Greetings, Summary: This plugin is intended solely to learn JavaScript, not to really use. Hence it is posted in Learning JavaScript forum on purpose.
Archived First Post
Greetings,
Thanks,
Joy Diamond.
P.S.: For more details on why to "use strict" mode please see Strict Mode by Mozilla Development Network
Summary:
- This plugin is intended solely to learn JavaScript, not to really use.
- Hence it is posted in Learning JavaScript forum on purpose.
I wrote my first plugin to show why to "use strict" mode:
Output:- Basically strict mode catches accidental bugs in your program & saves hour of wasting time chasing bugs.
- In the example given, I am trying to assign to variables named 'bug' & 'dog'.
- Due to bad coding it creates a global variable 'bug' (instead of local one if I had use the 'var' keyword).
- However, in the second example due to "strict mode" it catches my bug & does not create a global variable 'dog'.
Downloadable:
You can download the plug in from this link: Bloodstone.js
Please let me know if anything is unclear.
Thanks,
Joy Diamond.
Code:
//
// Copyright (c) 2017 Joy Diamond. Licensed under the MIT License.
// BLOODSTONE: Bugs Lack Object Oriented Development. Strict Testing Obligatory, No Errors
//
// This plugin demonstrates why to use strict mode:
// For more details please read: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
//
//
// Since this plugin is only for demo purposes in the Developer Tools:
// Bring up Developer tools by default in test mode.
//
if (Utils.isOptionValid('test') && Utils.isNwjs()) {
if (Utils.RPGMAKER_VERSION == '1.5.1') { // Is this RPG Maker MV 1.5.1?
// Show developer tools (nw.js older version)
require('nw.gui').Window.get().showDevTools()
} else {
// Show developer tools (nw.js 0.25.4 version)
nw.Window.get().showDevTools(false)
}
}
// BAD: Bad coding style
(function BAD(){
// "use strict" // Bad coding style: missing strict mode!!!
bug = 666 // Will *NOT* throw an error
})();
// GOOD: Good coding style
(function GOOD(){
"use strict" // Strict mode helps catch JavaScript errors, very useful
window.cat = 777 // Here we create a global on purpose using `window.cat`
dog = 888 // Will throw an error, and not create `dog` by mistake
})();
//--------------------------------------------------------+
// This code is formatted for clarity. |
// Hence this code does not use unnecessary semicolons. |
// Reasoning: https://mislav.net/2010/05/semicolons/ |
//--------------------------------------------------------+
// The full MIT License is available here: https://github.com/Rhodolite/Opal/blob/master/LICENSE
/*: @plugindesc Bugs Lack Object Oriented Development. Strict Testing Obligatory, No Errors */
P.S.: For more details on why to "use strict" mode please see Strict Mode by Mozilla Development Network
Downloads / Referenced Files
Log in to download
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadLicense / Terms Note
// Copyright (c) 2017 Joy Diamond. Licensed under the MIT License. // BLOODSTONE: Bugs Lack Object Oriented Development. Strict Testing Obligatory, No Errors // // This plugin demonstrates why to use strict mode:
Creator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
0
replies
1
view
Topic Summary
Loading summary...