//工廠模式promise
function newObject(color,age,...arg){
let obj= new Object()
obj.color= color;
obj.age = age;
...arg;
return obj;
}ide
//單例模式
function getinstance=(function(){
let object;
return function(){
if(object ==undefined){
obj = new doSome()
return object;
}
}
})();
使用
let instance = getinstance()代理
//觀察者模式code
let mypromise = function(){
return new Promise((resolve,reject)=>{
if(true){
resolve(dosometing)
}else{
reject('error')
}對象
})
}
//使用
mypromise.then(res=>{console.log(res)})get
//策略模式
let object = {
"fist":function(){
dosmething;
},
"second":function(){
dosmething;
},
"thired":function(){
doSomething;
}
}
//代理模式it
function isSend(message){
console.log(message+"目標對象")
}
function proxyObject(message){
let message = dosometing(message);
isSend(message)
}io