0

I have scrip with this structure:

define('game-logic/clib',[], function () {

var audio = null;

return {

   //Some functions....

  localOrDef: function(name, def) 
  {
       /....
  },

}

});

And I have no idea, how this 'define' stuff on top works, I want to understand it, as I want to rewrite this script in such a way, so that I could call my functions like Clib.localOrDef(name,def), by including it with other scripts simply using:

 "script type="text/javascript" src="js/clib.js"></script>"

This 'define('game-logic/clib',[], function ()' - how to replace it with the call to the static class?

user2426290
  • 382
  • 2
  • 14

1 Answers1

0

To keep it simple - define keyword comes usually from RequireJS framework and it is used to guarantee that particular dependencies are met when you call them, e.g. JQuery is loaded when you want to use it. More info could be found on projects homepage: http://requirejs.org/

Each module used by RequireJS is written in AMD way. More info could be found here: https://github.com/amdjs/amdjs-api/blob/master/AMD.md

If you just want to call you functions in an object way, you could use prototype. More info could be found e.g. here: http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/ or here: http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/

SzybkiSasza
  • 1,591
  • 12
  • 27