Well world, because the demo actually lets you see how plugins are generated I would suggest some template, just copy paste it to any plugin you may want to use and then use it.
While probably final plugins may be different, at least we can use the idea of plugin from jQuery and underscore and really... 99% of JS engines, adding some ideas from previous maker and Yanfly's script in the demo:
//=============================================================================// <Plugin Name>// By <Author>// <filename>.js// Version: <version>// Released under <your license>//=============================================================================// This is the imported variable, like you usevar Imported = Imported || {};Imported["MyPluginName"] = true; // or instead of true, a version string, like "1.0.1"// This variable will work as your module, like yanfly's YEP, for examplevar MyName = MyName || {};(function ($) { "use strict"; // Forcing strict mode, I recommend this for YOUR OWN SAFETY... //My code starts here // some example function privateFunction() { alert("public"); }; function publicFunction() { privateFunction(); }; function otherPublic() { $.publicFunction(); // We use $ because it will be our "public space" }; // we export our values here $.publicFunction = publicFunction; $.otherPublic = otherPublic;})(MyName); // Do you see the MyName here, that is the value of $ above.
This way we won't pollute much the global namespace and we can live al happily together...
And finally a cleaner version of it:
//=============================================================================// <Plugin Name>// By <Author>// <filename>.js// Version: <version>// Released under <your license>//=============================================================================// This is the imported variable, like you usevar Imported = Imported || {};Imported["MyPluginName"] = true; // or instead of true, a version string, like "1.0.1"// This variable will work as your module, like yanfly's YEP, for examplevar MyName = MyName || {};// Plugin starts here(function ($) { "use strict"; // Forcing strict mode // Imports // Private variables // Public variables // Private classes // Private functions // Public classes // Public functions // Export area})(MyName); // Do you see the MyName here, that is the value of $ above.// Plugin ends hereOf course I WILL update it on Oct 23... when I can get a full peek about the classes, but this is a good start.
You don't have too do it, but it's clean 😛
FAQ:
Why are you using $ as a parameter?
because it's shorter than MyName, you can use anything, but using $ will help you (and others) than "this is a function from myself"
Of course, using "me", "thisPackage" or not usinf $ is fine, but it is actually a really clever way to remember "this is mine"
Calling from other modules you will have to call it from its full name:
YEP.something()of course, I suggest your classes extensions like "SpriteSomething" go inside your module:
// blah blah(function ($) { function ChildSprite() { // blah blah blah }; ChildSprite.prototype = Object.create(Sprite.prototype); ChildSprite.prototype.constructor = ChildSprite; $.ChildSprite = ChildSprite; // continue...What is "use strict"; and Why I should use it?
Use strict is activating strict mode on your code strict mode doesn't make your code slower or faster, not it protects you from code outside, but it protects you by any kind of "code smell" you can do. Please, read the article about strict mode, it will guide you about and make you stop fearing about it, even more, you will embrace it probably when you start doing real code.
See ya on Oct 23th
While probably final plugins may be different, at least we can use the idea of plugin from jQuery and underscore and really... 99% of JS engines, adding some ideas from previous maker and Yanfly's script in the demo:
//=============================================================================// <Plugin Name>// By <Author>// <filename>.js// Version: <version>// Released under <your license>//=============================================================================// This is the imported variable, like you usevar Imported = Imported || {};Imported["MyPluginName"] = true; // or instead of true, a version string, like "1.0.1"// This variable will work as your module, like yanfly's YEP, for examplevar MyName = MyName || {};(function ($) { "use strict"; // Forcing strict mode, I recommend this for YOUR OWN SAFETY... //My code starts here // some example function privateFunction() { alert("public"); }; function publicFunction() { privateFunction(); }; function otherPublic() { $.publicFunction(); // We use $ because it will be our "public space" }; // we export our values here $.publicFunction = publicFunction; $.otherPublic = otherPublic;})(MyName); // Do you see the MyName here, that is the value of $ above.
This way we won't pollute much the global namespace and we can live al happily together...
And finally a cleaner version of it:
//=============================================================================// <Plugin Name>// By <Author>// <filename>.js// Version: <version>// Released under <your license>//=============================================================================// This is the imported variable, like you usevar Imported = Imported || {};Imported["MyPluginName"] = true; // or instead of true, a version string, like "1.0.1"// This variable will work as your module, like yanfly's YEP, for examplevar MyName = MyName || {};// Plugin starts here(function ($) { "use strict"; // Forcing strict mode // Imports // Private variables // Public variables // Private classes // Private functions // Public classes // Public functions // Export area})(MyName); // Do you see the MyName here, that is the value of $ above.// Plugin ends hereOf course I WILL update it on Oct 23... when I can get a full peek about the classes, but this is a good start.
You don't have too do it, but it's clean 😛
FAQ:
Why are you using $ as a parameter?
because it's shorter than MyName, you can use anything, but using $ will help you (and others) than "this is a function from myself"
Of course, using "me", "thisPackage" or not usinf $ is fine, but it is actually a really clever way to remember "this is mine"
Calling from other modules you will have to call it from its full name:
YEP.something()of course, I suggest your classes extensions like "SpriteSomething" go inside your module:
// blah blah(function ($) { function ChildSprite() { // blah blah blah }; ChildSprite.prototype = Object.create(Sprite.prototype); ChildSprite.prototype.constructor = ChildSprite; $.ChildSprite = ChildSprite; // continue...What is "use strict"; and Why I should use it?
Use strict is activating strict mode on your code strict mode doesn't make your code slower or faster, not it protects you from code outside, but it protects you by any kind of "code smell" you can do. Please, read the article about strict mode, it will guide you about and make you stop fearing about it, even more, you will embrace it probably when you start doing real code.
See ya on Oct 23th