zoukankan      html  css  js  c++  java
  • js对象的继承

    /*js对象的继承*/

    /*----------------------------
    *混合方式
    *----------------------------
    */
    function ClassA(sColor)
    {
        
    this.Color=sColor;
    }
    ClassA.prototype.showColor
    =function()
    {
        alert(
    this.Color);
    }

    function ClassB(sColor,sName)
    {
        ClassA.call(
    this,sColor);
        
    this.name=sName;
    }
    ClassB.prototype
    =new ClassA();
    ClassB.prototype.showName
    =function()
    {
        alert(
    this.name);
    }

    /*----------------------------
    *不能采用动态原型方式继承
    *----------------------------
    */



    /*----------------------------
    *引入zInherit.js,实现继承
    *----------------------------
    */



    /*----------------------------
    *引入xbObjects.js,实现继承
    *----------------------------
    */
    //如下:

    //基类
    _classes.registerClass("ClassA");  //注册类

    function ClassA(color)
    {
        _classes.defineClass(
    "ClassA",prototypeFunction); //定义类

        
    this.init(color);    //对参数进行初始化

        
    function prototypeFunction()
        {
            ClassA.prototpye.init
    =function(color)
            {
                
    this.parentMethod("init");
                
    this.color=color;
            };

            ClassA.prototype.showColor
    =function()
            {
                alert(
    this.color);
            }
            
    //..
        }
    }

    //继承类
    _classes.registerClass(继承类,基类);  //注册类


    //余下的和上面写法差不多
  • 相关阅读:
    MyString
    Django疑难问题
    mysql 疑难问题-django
    python时间转换 ticks-FYI
    django建议入门-FYI
    Python风格规范-FYI
    scrum敏捷开发☞
    git基本命令
    centos下的安装mysql,jdk
    memcached for .net on windows
  • 原文地址:https://www.cnblogs.com/jackhuclan/p/1150091.html
Copyright © 2011-2022 走看看