JS工厂模式
来源:互联网 发布:vue.js 移动端ui框架 编辑:程序博客网 时间:2024/05/17 01:43
var page = page || {};page.dom = page.dom || {};//子函数1:处理文本page.dom.Text = function () { this.insert = function (where) { var txt = document.createTextNode(this.url); where.appendChild(txt); };};//子函数2:处理链接page.dom.Link = function () { this.insert = function (where) { var link = document.createElement('a'); link.href = this.url; link.appendChild(document.createTextNode(this.url)); where.appendChild(link); };};//子函数3:处理图片page.dom.Image = function () { this.insert = function (where) { var im = document.createElement('img'); im.src = this.url; where.appendChild(im); };};
工厂方法接口
page.dom.factory = function (type) { return new page.dom[type];}
调用方式
var o = page.dom.factory('Link');o.url = 'http://www.csdn.com';o.insert(document.body);
- JS工厂模式
- JS工厂模式介绍
- js 工厂模式
- js实现工厂模式
- js工厂方法模式
- js的工厂模式
- JS工厂模式
- JS 工厂模式
- JS简单工厂模式
- js简单工厂模式
- js工厂方法模式
- js抽象工厂模式
- JS中的工厂模式
- js 简单工厂模式
- js 抽象工厂模式
- JS 设计模式----工厂模式
- JS设计模式-工厂模式
- JS设计模式-工厂模式
- SQLServer启动和关闭bat脚本
- jQuery语法总结和注意事项
- 昂山素季 Aung San Suu Kyi
- OpenRTMFP/Cumulus Primer(10)IO 管理之流缓冲区
- OpenRTMFP/Cumulus Primer(11)IO 管理之IO流
- JS工厂模式
- TextView scrollbars setting
- Java泛型简明教程
- 并发
- 配置logging conf/log4j.properties
- 二次大战时,罗死福,丘鸡儿
- 某人天天在学盲文
- 妙用BlackBerry的GlobalEvent
- 霍森先生和他的妻儿们开着一辆老爷车去郊游