javascript抽象工厂模式

时间:2023-02-13 11:14:33
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>抽象工厂模式</title>
</head>
<body>
<script>
// a.邮件的类
function MaiSender(){
this.to = "";
this.title = "";
this.content ="";
}
MaiSender.prototype.send = function(){ }
// b. 邮件工厂类;
function MailFactory(){};
MailFactory.prototype.produce = function(){
return new MailFactory();
}
// c.实例化工厂
var factory = new MailFactory();
// d、调用工厂实例化方法,
var sender = factory.peoduce();
// e、对实例化的对象属性进行复制;
sender.to = 'xxx#sss.com';
sender.title = "xxxxx";
sender.content ="content";
sender.send();
</script>
</body>
</html>