码迷,mamicode.com
首页 > 其他好文 > 详细

安全模式的工厂模式

时间:2018-09-18 22:50:19      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:html   cti   color   htm   instance   UNC   php   ret   顺序   

var Factory = function(type,content){
        if (this instanceof Factory)
        {
            var s = new this[type](type,content);//运算符优先顺序
            return s;
        }else {
            return new Factory(type,content);
        }
    }

    Factory.prototype = {
        html:function(type,content){
            this.content = content;
            this.type = type;
            this.show = function(){
                console.log(this.type+this.content);
            }
        },
        php:function(type,content){
            this.content = content;
            this.type = type;
            this.show = function(){
                console.log(this.type+this.content);
            }
        }
    }
    var p1 = Factory(‘html‘,‘哪家强?‘);
    p1.show();
    var p2 = Factory(‘php‘,‘真的不错!‘);
    p2.show();

 

安全模式的工厂模式

标签:html   cti   color   htm   instance   UNC   php   ret   顺序   

原文地址:https://www.cnblogs.com/jokes/p/9671141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!