Hello world
In the first example, we will create a "Hello world" widget, that simply shows some text. We start by initialising the pax name space:
// Create the namespace
var pax = pax || {};
pax.widget = pax.widget || {};
pax.widget.hello = pax.widget.hello || {};
var pax = pax || {};
pax.widget = pax.widget || {};
pax.widget.hello = pax.widget.hello || {};
Next we create our init method:
// "Controller" method
pax.widget.hello.init = function( target, args ) {
var model = pax.widget.hello.model( target, args );
pax.widget.init( {
target: target,
model: model,
template: pax.widget.hello.template()
} ).render(); // This renders the widget
};
pax.widget.hello.init = function( target, args ) {
var model = pax.widget.hello.model( target, args );
pax.widget.init( {
target: target,
model: model,
template: pax.widget.hello.template()
} ).render(); // This renders the widget
};
// "View" method
pax.widget.hello.template = function() {
return "Hello [:= name :]";
};
pax.widget.hello.template = function() {
return "Hello [:= name :]";
};
// "Model" method
pax.widget.hello.model = function( target, args ) {
return pax.defaultArgs( {
name: 'world' // Default the name to 'world', if none is specified
}, args );
};
pax.widget.hello.model = function( target, args ) {
return pax.defaultArgs( {
name: 'world' // Default the name to 'world', if none is specified
}, args );
};
Read on to see our widget in action!




