#Framework Factory#
Framework factory is a tiny, well-designed and yet powerful factory framework for developing modern Object Oriented JavaScript based class libraries, frameworks and applications. Its pluggable architecture and amazing combination of tools (configuration handling, read-only members, events, properties, class inheritance, and much more) gives you enough power to create robust applications which are compatible with your favorite JavaScript library (jQuery, mooTools, underscore), and your favorite platform (Modern Browsers, NodeJS).
Following example shows how a simple farmework called myFramework is created.
Create a new Framework called myFramework through FrameworkFactory.create
function. This function accepts configuration object.
var myFramework = FrameworkFactory.create({
name: "myFramework",
version: "1.0.0"
});
Create new class called Person within myFramework namespace.
myFramework.Person = myFramework.Class({
firstName: myFramework.attribute("first-name"),
lastName: myFramework.attribute("last-name"),
fullName: myFramework.readonly({
get: function () {
return this.firstName + " " + this.lastName;
}
}),
start: myFrmaework.event();
work: function () {
this.trigger("start");
}
});
Create another class called myFramework.Employee which is derived from
myFramework.Person.
myFramework.Employee = myFramework.Person.extend({
department: myFramework.readonly(),
employeeCode: myFramework.property({
get: function () {
return this._employeeCode;
},
set: function(v) {
if (v !== this._employeeCode) {
this._employeeCode = v;
if (employeeCode < 100) {
this._department = "Sales";
}
else {
this._department = "Marketing";
}
}
}
}),
init: function (employeeCode) {
if (employeeCode) {
this.employeeCode = employeeCode;
}
else {
throw new Error("Invalid employeeCode");
}
},
work: fuction() {
console.log("Employee started working.");
this.base();
}
});
Some applications of dummy framework myFramework.
var p1 = new myFramework.Person();
p1.firstName = "Peter";
p1.lastName = "Parker";
console.log(p1.fullName);
p1.fullName = "Peter Thompson";
var e1 = new myFramework.Employee(10);
console.log(e1.employeeCode);
console.log(e1.department);
console.log(e1 instanceof Employee)
console.log(e1 instanceof Person)
console.log(e1.fullName);
##Licence and Copyright ##
© 2011-2017 Maniar Technologies Private Limited, MIT license