首页 > 编程语言 > 详细

javascript 简单工厂

时间:2015-03-29 08:16:18      阅读:109      评论:0      收藏:0      [点我收藏+]
function detail() {
    this.imgArr = [];
    this.codeArr = [];
}
detail.prototype.addimg = function(img) {
    this.imgArr.push(img);
};
detail.prototype.addcode = function(code) {
    this.codeArr.push(code);
};
detail.prototype.show = function() {
    $.each(this.imgArr, function(index, val) {
        $(‘#resDiv‘).html($(‘#resDiv‘).html() + val);
    });
    $.each(this.codeArr, function(index, val) {
        $(‘#resDiv‘).html($(‘#resDiv‘).html() + val);
    });
};
var detailFactory = {};
var d1 = new detail();
d1.addimg(‘img1‘);
d1.addcode(‘code1‘);
var d2 = new detail();
d2.addimg(‘img2‘);
d2.addcode(‘code2‘);

detailFactory.df1 = d1;
detailFactory.df2 = d2;

$(function() {
    var r = Math.random();
    if (r > 0.5) {

        detailFactory.df2.show();
    } else {

        detailFactory.df1.show();
    }


});

 

javascript 简单工厂

原文:http://www.cnblogs.com/stono/p/4375184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!