<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>桥接模式</title>
</head>
<body>
<script>
//多维变量类
//运动单元
function Speed(x, y) {
this.x = x;
this.y = y;
}
Speed.prototype.run = function() {
console.log('运动起来');
}
//着色单元
function Color(c1) {
this.color = c1;
}
Color.prototype.draw = function() {
console.log('绘制色彩');
}
//变性单元
function Shape(sp) {
this.shape = sp;
}
Shape.prototype.change = function() {
console.log('改变形状');
}
//说话单元
function Speek(wd) {
this.word = wd;
}
Speek.prototype.say = function() {
console.log('书写字体');
}
//球
function Ball(x, y, c) {
//实现运动单元
this.speed = new Speed(x, y);
//实现着色单元
this.color = new Color(c);
}
Ball.prototype.init = function() {
this.speed.run();
this.color.draw();
}
//人
function People(x, y, f) {
this.speed = new Speed(x, y);
this.font = new Speek(f);
}
People.prototype.init = function() {
this.speed.run();
this.font.say();
}
//精灵
function Spirite(x, y, c, s) {
this.speed = new Speed(x, y);
this.color = new Color(c);
this.shape = new Shape(s);
}
Spirite.prototype.init = function() {
this.speed.run();
this.color.draw();
this.shape.change();
}
window.onload = function() {
var p = new People(10, 12, 16);
p.init();
}
</script>
</body>
</html>
JavaScript设计模式(十一)【桥接模式】
最新推荐文章于 2024-09-26 10:11:24 发布