原始写法:
var LoginAlert=function(text){
this.content=text
}
LoginAlert.prototype.show=function(){
}
var userNameAlert=new LoginAlert('用户名不能多于16个字母或数字')
userNameAlert.show()
var passwordAlert=new LoginAlert('输入密码不正确!')
passwordAlert.show()
var loginconfirm=function(text){
this.content=text
}
loginconfirm.prototype.show=function(){
}
var loginFailconfirm=new loginconfirm("你的用户名不存在,请重新输入")
loginFailconfirm.show()
简单工厂模式写法1:
var Basketball=function(){
this.intro='篮球盛行于美国'
}
Basketball.prototype={
getMember:function(){
console.log("每队需要5名队员")
},
getBallsize:function(){
console.log('篮球很大')
}
}
var Football=function(){
this.intro='足球世界范围内流行'
}
Football.prototype={
getMember:function(){
console.log("每个队伍需要11名队员")
},
getBallsize:function(){
console.log("足球很大")
}
}
var Tennis=function(){
this.intro='每年有很多网球系列赛'
}
Tennis.prototype={
getMember:function(){
console.log('每个队伍需要1名队员')
},
getBallsize:function(){
console.log('网球很小')
}
}
var sportsFactory=function(name){
switch(name){
case 'NBA':
return new Basketball();
case 'wordcup':
return new Football();
case 'Frenchopen':
return new Tennis();
}
}
var footnall=sportsFactory('wordcup')
console.log(footnall)
console.log(footnall.intro)
footnall.getMember()
简单工厂模式写法2:
function createPop(type,text){
var o=new object()
o.content=text;
o.show=function(){
};
if(type=='alert'){
}
if(type=='prompt'){
}
if(type=='confirm'){
}
return o;
}
var userNameAlert=createPop('alert','用户名只能是26个字母和数字')