• 我的书中的部分函数


    var GLOBAL = {};

    GLOBAL.namespace = function(str){

    var arr = str.split("."),o = GLOBAL;

    for (i=(arr[0] == "GLOBAL") ? 1 : 0; i<arr.length; i++) {

        o[arr[i]]=o[arr[i]] || {};

        o=o[arr[i]];

    }

    }

    GLOBAL.namespace("Dom");

    GLOBAL.Dom.getElementsByClassName = function(str,root,tag){

    if(root){

        root = typeof root == "string" ? document.getElementById(root) : root;

    } else {

        root = document.body;

    }

    tag = tag || "*";

    var els = root.getElementsByTagName(tag),arr = [];

    for(var i=0,n=els.length;i<n;i++){

        for(var j=0,k=els[i].className.split(" "),l=k.length;j<l;j++){

          if(k[j] == str){

            arr.push(els[i]);

            break;

          }

        }

    }

    return arr;

    }

    GLOBAL.namespace("Event");

    GLOBAL.Event.on = function(node,eventType,handler,scope){

    node = typeof node == "string" ? document.getElementById(node) : node;

    scope = scope || node;

    if(document.all){

        node.attachEvent("on"+eventType,function(){handler.apply(scope,arguments)});

    } else {

        node.addEventListener(eventType,function(){handler.apply(scope,arguments)},false);

    }

    }

    function extend(subClass,superClass){

    var F = function(){};

         F.prototype = superClass.prototype;

         subClass.prototype = new F();

         subClass.prototype.constructor = subClass;

         subClass.superclass = superClass.prototype;

         if(superClass.prototype.constructor == Object.prototype.constructor){

              superClass.prototype.constructor = superClass;

         }

    }

    function Animal(name){

    this.name = name;

    this.type = "animal";

    }

    Animal.prototype = {

    say : function(){

    alert("I'm a(an) " + this.type + " , my name is " + this.name);

    }

    }

    function Bird(name){

    this.constructor.superclass.constructor.apply(this,arguments);

    this.type = "bird"

    }

    extend(Bird,Animal);

    Bird.prototype.fly = function(){

    alert("I'm flying");

    }

    var canary = new Bird("xiaocui");

    canary.say(); // I’m a(an) bird , my name is xiaocui

    canary.fly(); // I’m flying

  • 相关阅读:
    内网穿透(Frp)-拯救没有公网IP的你
    用Windows远程桌面连接树莓派的方法
    TensorFlow 1.9开始支持树莓派
    树莓派制作遥控小车-新手教程
    Layui 一个页面包含多个table时不展示分页条
    MVC 通过@符号把数据赋值给jQuery对象
    jQuery 批量为表单元素赋值
    layui分页组件,一直在调用方法的解决办法
    layui 表格复选框不居中解决办法
    JQuery 解决遮罩层下内容可以滚动问题
  • 原文地址:https://www.cnblogs.com/cly84920/p/4426794.html
Copyright © 2020-2023  润新知