Own "module" with functions inside

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
In ace, we have something like this:

module Sample def initialize #stuff here endendif we translate this in JS, how do we exactly do it?
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
var Sample = {


initialize: function() {


// stuff here


}


};
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Thanks. Works perfectly :D
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
// Preferred way (for me)class x {}module.exports = x;or:

// ES5 "class" wayvar x = {   functionName: function(){}}module.exports = x;or

// prototypesfunction something(){}something.prototype.constructor = function() {};module.exports = something;Notice the 

module.exports = whatEver;it creates a module that is then not global, in the sense that everything is scoped to that module. You can then use something like require to require your modules in to other modules:

require('./whatEver')whatEver here is the name of the file containing the module. 

These are es6 concepts How ever these are simple concepts to understand. They do require something like browserify with the bablify extension to compile in to es5 code. The code will be but ugly, but thats what github is for.

This is the true concept of modules.

If you want something like yanfly:

var Imported = Imported || {};Imported.YEP_BaseTroopEvents = true;var Yanfly = Yanfly || {};Yanfly.BTE = Yanfly.BTE || {};You create with objects with subjects that hold the information you want, how ever I have never seen this done in web development .... this:

var Yanfly = Yanfly || {};I've seen done and I tend to refactor the code to move on to the actual concept of "modules"
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,845
Messages
1,016,961
Members
137,561
Latest member
JaCrispy85
Top