Loading

javascript 简单工厂

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();
    }


});

 

posted @ 2015-03-29 06:58  stono  阅读(134)  评论(0编辑  收藏  举报