I would like to ask to be able to build one, based on the the inherited patterns or syntactic sugar, it is not a large framework.Classification Ajax code to maintain the MVC architecture.
I hope it can operate, such as sample code, but I do not know Javascript can do this?
/* Just for demonstration architecture may be constructed with an object or function */
var Prototype = (){
this.Controller = {/*...*/};
this.Model = {/*...*/};
this.View = {/*...*/};
this.Constructor = function(){/* auto binding, like run this.Controller.update */};
/*...*/
};
var a = new Prototype; /* or $.extend, object.create, etc */
/* Create a function */
a.Controller.update = function(){
$('#button').bind('click', function(){
this.Model.update(); // Equivalent a.Model.update()
this.Model.list(); // Equivalent a.Model.list()
b.Model.del(); // Can call other instance of the function
});
}
a.Model.update = function(){
$.ajax('json source', function(data){
this.View.update('json parse'); // Equivalent a.View.update()
});
}
a.View.update = function(obj){
/* Do something about the DOM */
}
/* Can be controlled by the other controller */
a.Model.list = function(){
this.View.list('json parse'); // Equivalent a.View.list()
}
a.View.list = function(obj){
/* Do something about the DOM */
}
var b = new Prototype;
b.Controller.del = function(){
$('#del').bind('click', function(){
this.Model.del(); // Equivalent b.Model.del()
}
}
b.Model.del = function(){
$.ajax('json source', function(data){
this.View.del('json parse'); // Equivalent b.View.del()
});
}
b.View.del = function(){
/* Do something about the DOM */
}
a.Constructor(); //init
b.Constructor();