zoukankan      html  css  js  c++  java
  • YUI中js的继承示例

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://cn.yimg.com/i/yui/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    </head>
    <script type="text/javascript">
    function RichWin()
    {
        this.tpl = "adang";
        this.alert = function(){alert(this.tpl)};
        var testStr = "hello world";
        this.show = function(){alert(testStr)};
    }

    function Tool_common()
    {
        this.constructor.superclass.constructor.call(this);
        this.type = "tool_common";
    }
    YAHOO.lang.extend(Tool_common,RichWin);

    var obj = new Tool_common();
    alert(obj.testStr);
    obj.show();
    </script>
    <body>
    </body>
    </html>


    一个简单的例子。在这个例子中,可以看到,用var 定义的私有变量,是不能被继承的。所有能被继承的,一定是通过this关键字,在内在地址中和这个对象的地址捆在一起的变量。因为复合对象传的不是值而是址,所以通过一个公开的方法,方法内部调用私有属性,来间接访问私有变量。这一点和正式的oop语言倒是没两样。
  • 相关阅读:
    泰勒综合
    滤波器、窗等的系数为什么是对称的?
    l'alphabet en francais
    弄清for循环的本质
    js中的闭包
    js中用正则表达式
    java Calendar
    Android实现XML解析技术
    junit4 详解
    redhat vi 命令
  • 原文地址:https://www.cnblogs.com/cly84920/p/4427070.html
Copyright © 2011-2022 走看看