zoukankan      html  css  js  c++  java
  • Javascript设计模式(一)Facade

    外观模式

    //为复杂的子系系统提供一个更高级的统一接口

    //外观模式实现兼容

    function addEvent(dom,type,fn){
            if(dom.addEventListener){
                dom.addEventListener(type,fn,false);
            }else if(dom.attachEvent){
                dom.attachEvent('on'+type,fn);
            }else{
                dom['on'+type]=fn;
            }
        }
    

    //外观模式建立代码库

     var A={
            g:function(id){
                return document.getElementById(id);
            },
            css:function(id,key,value){
                document.getElementById(id).style[key]=value
            },
            attr:function(id,key,value){
                document.getElementById(id)[key]=value
            },
            html:function(id,html){
                document.getElementById(id).innerHTML=html;
            },
            on:function(id,type,fn){
                document.getElementById(id)['on'+type]=fn;
            }
        }
        A.css("box","background","red");
        A.attr("box","className","boxStyle");
        A.html("box","张三");
        A.on("box","click",function(){
            console.log(2222)
        })
  • 相关阅读:
    bzoj3280
    bzoj3876
    洛谷 p1625
    bzoj1407
    bzoj1227
    bzoj1477 && exgcd学习笔记
    bzoj1345
    c#程序的config文件问题
    思维角度的重要性
    python异步初步窥探
  • 原文地址:https://www.cnblogs.com/dangou/p/7295092.html
Copyright © 2011-2022 走看看