JSFiddle - React, Tailwind, and code Playground

by jim28791

HTML

<div><a href="http://fb.com/bluebocat" target="_blank">藍寶粉絲頁</a></div>

JavaScript

function cat(){
    this.version='0.3a'; //製作貓的版本
    this.make=function(){//設定完成後就可以建立喵星人
        alert(this.name);
    }
}

cat.create_britshshorthair=function(name){ //建立品種  英國短毛貓
    this.name=name;
    this.type_name='Britsh Short Hair';
    alert('英國短毛貓'); //藍寶的品種
}

cat.create_britshlonghair=function(name){  //建立品種  英國長毛貓
    this.name=name;
    this.type_name='Britsh Long Hair';
    alert('英國長毛貓'); //Lindi的品種
}

cat.factory=function(type,name){
    if(typeof cat[type] !== 'function'){
        throw{
            'name':'error',
            'msg':'not exist'
        }
        return false;
    }else{
        if(typeof cat[type].prototype !=='function'){
            cat[type].prototype=new cat();
        }
        var newobj=new cat[type](name);        

        return newobj;
    }
}

var bluebo=cat.factory('create_britshshorthair','bluebo');//建立一隻英國短毛貓
var lindi=cat.factory('create_britshlonghair','lindi');//建立一隻英國長毛貓

bluebo.make();
lindi.make();
console.log(bluebo);
console.log(lindi);