• 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语言倒是没两样。
  • 相关阅读:
    PHP获取时间or戳?
    滤镜灰CSS
    css3 文字渐变色
    除指定区域外点击任何地方隐藏DIV
    margin-top bug 处理方案
    基于Bootstrap好用的瀑布流
    初始数据库
    协程
    粘包及解决方案
    log日志的三种方式
  • 原文地址:https://www.cnblogs.com/cly84920/p/4427070.html
Copyright © 2020-2023  润新知