DCI 的 註冊場景Context

liontseng發表於2011-05-03
我是用簡單的JS程式碼構建DCI的程式碼,希望各位和Banq大哥給與分析和指正。

/*----------註冊角色BEGIN-----------------*/
require("ext");

function RegerRole(user){
this.user = user;
Object.merge(this,user);
Object.merge(this,user.__proto__);
}

RegerRole.prototype.reg = function(callback){
userRepo.save(this.user);
callback(err);
}
/* ------------------ END -------------------- */

/*---------- 註冊場景 -----------------*/
function RegContext( loginname , password , confirm ){
this.loginname = loginname;
this.password = password;
this.confirm = confirm;
}

var o = RegContext.prototype;

o.interact = function(callback){
var user = userFactory.create({loginname:this.loginname,password:this.password});
var reger = new RegerRole(user,this.confirm);
reger.reg(callback) ;
}

/* ------------------ END -------------------- */

呼叫程式碼 >>
function callback(){ ... }
var cxt = new RegContext(...);
cxt.interact(callback);

相關文章