zoukankan      html  css  js  c++  java
  • 我的书中的部分函数

    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

  • 相关阅读:
    UOJ.26.[IOI2014]Game(交互 思路)
    Good Bye 2016 F.New Year and Finding Roots(交互)
    Codeforces.835E.The penguin's game(交互 按位统计 二分)
    Codeforces.744B.Hongcow's Game(交互 按位统计)
    Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
    正睿OI 提高 Day1T3 ZYB玩字符串(DP)
    划分vlan
    2三层交换机实现vlan间的路由
    交换机基础-交换机远程telnet
    自动化运维环境的搭建问题处理
  • 原文地址:https://www.cnblogs.com/cly84920/p/4426793.html
Copyright © 2011-2022 走看看