Module Ninja is Dynamic Metaprogramming JavaScript Library, that I made in my free time.
I believe that it is a piece of code with a great potential to become something very big.
2. WHAT IS MODULE NINJA .JS
* Module Ninja is an independant JavaScript library.
* It is an extension to the JavaScript language, simplifying the
tasks of metaprogramming and dynamic programming.
* It can be used to dynamically generate strongly-typed, closed
scope class modules, that have access modifiers, content validators,
static & object functions, and much more, just like the classes in any
traditional OOP language.
3. WHAT DOES MODULE NINJA
PROVIDE
* Fluent usage API (JQuery style)
* Fluent result API (The resulting module is also JQuery style)
* Code Generation (Write less – do more)
* Easy Dynamic JS (Go outside of the borders of the JS language)
* Meta Data (A module’s data can be read in predictable way)
* Easy Extending (Predefined ways of writing extension libraries)
6. CODE GENERATION
Want to see the code that was actually generated ?
Go to this link:
https://rawgit.com/Siko91/CawboyCoding--
Experimenting/master/moduleNinjaExperiments/Demo.html
7. EXAMPLE OF DYNAMIC JS
A class is a representation of an idea.
But it is not necessary an idea of the developer!
Let’s talk in code:
var complexClassMetaData = mn.class().className("ComplexClass")
.prop("value1", "string", "some default value");
complexClassMetaData = EditClassInADistantServer(complexClassMetaData);
var ComplexClass = complexClassMetaData.finalize();
8. METADATA USAGE
function ShowClassArrayAsTable(arrayOfModuleNinjaObjects){
var arrayOfPropNames = [];
for (var propIndex in arrayOfModuleNinjaObjects[0].metaData.props){
arrayOfPropNames.push(arrayOfModuleNinjaObjects[0].metaData.props[propIndex].name);
}
var $table = $("<table>");
for (var collumnIndex in arrayOfPropNames) { /* Create table columns */ }
for (var rowIndex in arrayOfModuleNinjaObjects){
for (var collumnIndex in arrayOfPropNames) { /* Get value & fill row cell */ }
}
$("body").append($table);
}
9. EXTENDING MODULE NINJA .JS
There are 3 main levels of extensions.
- Type definition extension (the simplest one – just add a new type validator)
Example: ”dayOfWeek” – it accepts ints/strings/etc as long as the manage to
represent one of the 7 days of the week. It always stores the value as a number
(1-7)
- Class/Module extension
Example: “toSerializableClass” – it adds a “Serialize” and “Deserialize” methods to
the class.
- ModuleNinja extension
Example: … whatever you want!
Have an idea for something completely different?
Your creativity will be more than welcome.