Question

I am studying the possibility of building Javascript applications in the Java / OSGi modularity style. I am sure I will not manage to actually reach the kind of flexibility that OSGi provides, but I would need to get to at least the following list:

  • split javascript code as modules, each module would lay in its own git repository
  • ideally, as little as possible dependencies between modules and definitely no circular dependencies between modules
  • have 2 or more "main" javascript applications that will use the modules described above

If I will manage to setup the above then I will probably want to be able to organize modules as layers like: core layer with several modules, ui layer, applications layer.

Are there any javascript libraries that help building the above setup? Is something like this possible in javascript?

Note: When I say javascript, I don't actually mean plain javascript. I am going to use a library like ExtJS or jQuery for the UI part at least.

Was it helpful?

Solution

Checkout RequireJS an implementation of Asynchronous Module Definition

OTHER TIPS

Since this question was answered javascript now has native implementaitons of classes and modules that can give you what you need without having to use a 3rd party library.

js modules alow you to have a module or code and import methods (or everything) from it (a bit like in python and ruby)

// utilities.js
function something () {
 // some great code 
}

export function util() {
  something();
}

//import a method
import {util} from "utilities.js";

// or import everything
import "utilities.js";

you can find more on es6 modules here

js classes are syntax suger over prototypal structure in js and can be used the same way as in more trandtional OOP languages

class MyClass {
  constructor() {
    // constructor code
  }

  add() {
    // some method
  }
}

var myObject = new MyClass();

You can find out more about es6 classes here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top