Jump to content

What is this magic ? About code organisation


MonsieurPixel
 Share

Recommended Posts

They're just extending the object PIXI itself, by the look of it. 

 

The way I'd do it is create a creation function that acts as the basis for your 'something' (in your example it would be PIXI a function fired when you instantiate it). Here's how you might do it from scratch (just writing this off the top of my head, sorry if it doesn't compile)

 

// mySomething.js

var mySomething = function(){

  return this;

};

 

// mySomething.doStuff.js 

mySomething.prototype.doStuff = function() {

 // stuff

};

 

<html>

<script src='mySomething.js'></script>

<script src='mySomething.doStuff.js'></script>

<script>

function onLoad() {

  // create a new instance of mySomething accessible in this scope

  var mySomething = new mySomething();

 // we are able to access doStuff because it was added in mySomething.doStuff.js

  mySomething.doStuff();

}

</script>

<body onload='onLoad()'>

</body>

</html>

Link to comment
Share on other sites

If you are speaking of having a clean codebase with logically separated javascript files - well I guess this is what we all do when our project grows.

 

To release a single compressed file of all your javascript files - there is no real magic behind it. Typically, this release version is automatically created within your build process, ie. a javascript minifier takes all your files, merges and compresses them into one single file.

 

There are numerous build tools and scripts around and it's usually a matter of taste which to choose. Personally I use an ant-script and Google Closure compiler - but I guess there exists a Grunt task for this, too.

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...