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语言倒是没两样。
  • 相关阅读:
    ISO 学习笔记 2015-03-15
    IOS 学习笔记 20150314
    IOS 学习日志 2015-3-13
    Letter Combinations of a Phone Number
    anagrams
    Pow(x, n)
    Distinct Subsequences
    Excel Sheet Column Number
    MIT 三课程
    c++ 重载,覆盖,重定义
  • 原文地址:https://www.cnblogs.com/cly84920/p/4427069.html
Copyright © 2011-2022 走看看