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

  • 相关阅读:
    【IDEA插件】—— 代码量统计工具Statistic
    【Funny Things】001——QQ循环发送消息
    【jmeter测试范例】001——TCP测试
    【Jmeter源码解读】003——TCP采样器代码解析
    【Jmeter源码解读】002——程序入口类NewDriver.java
    Eclipse点击空格总是自动补全代码怎么办,如何自动补全代码,代码提示
    路径中关于斜杠/和反斜杠 的区别
    eclipse查看JDK源码
    Navicat premium如何使用Oracle的OCI
    斐波那契查找不再迷惑
  • 原文地址:https://www.cnblogs.com/cly84920/p/4426793.html
Copyright © 2011-2022 走看看