<body>
将请求与实现解藕并封装成独立对象,从而使不同的请求对客户端的实现参数化
就是:对一些操作的封装,并提供简单高效的api(接口)
大多数的命令在一定程序上是简化操作方法的使用
<div id='app'>测试</div>
<script>
let command = {
width(dom, width){
dom.style.width = width + 'px'
},
// 定义统一的接口
execute(name, dom, width){
this[name](dom, width)
}
}
command.width(app, 200)
command.execute('width',app, 500)
</script>
</body>
网友评论