Jump to content

External Class (Module?)


N3RD
 Share

Recommended Posts

Hello again,

Is there a way to import external classes?

I come from a OOP Background and would like to split classes into single files.

The reason being its alot nicer and cleaner to have multiple smaller classes than

having 1 Main class which is 1000+ lines long. 

 

example:

Main.js
Obj1.js
Obj2.js
etc.....

Is the termonoligy here with panda.js Module instead of class?
If possible what would the implementation be?

Thank you!

N3RD
 

Link to comment
Share on other sites

Yes what you are looking for is Modules. You use them like this:

 

src/game/object1.js:

game.module('game.object1').require(// module dependencies// 'game.object2',// 'game.object3').body(function() {// your code    game.createClass('className', {        init: function(arg1,arg2) {        }});

you are not limited to src/game/ you can also have src/plugins/, src/functions/ and so on. and you call them like this:

game.module('directory.filename','directory1.directory2.filename2')
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...