Usage (client-side) :
On your Web page, load files : "Bootstrap,js", "Types,js", "Tools.js", "Namespaces.js", "Doodad.js", "Client.js".
On page load, create the root namespace :
var root = window.createRoot(window.DD_MODULES);
By default, Doodad is running in production mode, which disables every validations. You may want to enable them by also loading the file "Debug.js" and enabling object properties this way :
var root = window.createRoot(window.DD_MODULES, {startup: {settings: {enableProperties: true}}});
That's it. Now you can create your own objects.
Usage (server-side with nodejs) :
Installation : npm install doodad-js --save
By default, Doodad is running in production mode, which disables every validations. You may want to activate the development mode by setting the "NODE_ENV" environment variable :
Windows :
set NODE_ENV=development
Linux :
export NODE_ENV=development
Now, from Node.js, create the root namespace :
var root = require('doodad-js').createRoot();
That's it. Now you can create your own objects.
At startup, only bootstrap modules are loaded. But you can load other Doodad modules from this way :
const DD_MODULES = {};
require('doodad-js-io').add(DD_MODULES);
...
function onready() {
...
}
root.Doodad.Namespaces.loadNamespaces(onready, false, DD_MODULES);
Example 1 (inheritance):
var Turtle1 = root.Doodad.Object.$extend({
$TYPE_NAME: 'Turtle1',talk: root.Doodad.PUBLIC(function() {
return "Hi !";
}),
})var turtle = new Turtle1();
turtle.talk();
var Turtle2 = Turtle1.$extend({
$TYPE_NAME: 'Turtle2',talk: root.Doodad.OVERRIDE(function() {
return this._super() + " dOOOOdad";
}),
})turtle = new Turtle2();
turtle.talk();
Example 2 (interfaces):
var Turtles = root.Doodad.INTERFACE(root.Doodad.Class.$extend({
$TYPE_NAME: 'Turtles',talk: root.Doodad.PUBLIC(root.Doodad.METHOD()),
}));var Turtle1 = root.Doodad.Object.$extend(
Turtles,
{
$TYPE_NAME: 'Turtle1',talk: root.Doodad.OVERRIDE(function() {
return "Hi";
}),
})var Turtle2 = root.Doodad.Object.$extend(
Turtles,
{
$TYPE_NAME: 'Turtle2',talk: root.Doodad.OVERRIDE(function() {
return "Bonjour";
}),
})
Example 3 (mix-ins) :
var Turtles = root.Doodad.MIX_IN(root.Doodad.Class.$extend({
$TYPE_NAME: 'Turtles',talk: root.Doodad.PUBLIC(function() {
return "Hi";
}),
}));var Turtle1 = root.Doodad.Object.$extend(
Turtles,
{
$TYPE_NAME: 'Turtle1',
})
More examples:
Look at the source files. They make use of everything Doodad classes are able to.