首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript中模板方法方式的实现

2012-11-22 
javascript中模板方法模式的实现scriptfunction Panel () {this.el document.createElement(div)th

javascript中模板方法模式的实现

 <script>function Panel () {    this.el = document.createElement('div');    this.el.style.position = 'absolute';    this.initPosition();    this.initStyle();    document.body.appendChild(this.el);}Panel.prototype = {    initPosition: function () {},    initStyle: function () {}}function LeftPanel () {    this.base = Panel;    this.base();}LeftPanel.prototype = {    initPosition: function () {        this.el.style.left = '0';    },    initStyle: function () {        this.el.style.background = 'red';        this.el.style.width = this.el.style.height = '100px';    }}function RightPanel () {    this.base = Panel;    this.base();}RightPanel.prototype = {    initPosition: function () {        this.el.style.right = '0';    },    initStyle: function () {        this.el.style.background = 'green';        this.el.style.width = this.el.style.height = '100px';    }}var leftEl = new LeftPanel();var rightEl = new RightPanel();</script> 

热点排行