zoukankan      html  css  js  c++  java
  • javascript当中的构造函数的用法

    5)构造函数的用法:

    例 3.5.1

    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    </head>
    <script>
        function Student(name, age)
        {
            /* 马克-to-win:later on we can use it in
            var doc = new ActiveXObject( "Microsoft.XMLDOM" );
                        doc.async="false";
                        doc.load(str);
            when a property has a this, means that this property is a member property.
            */
            this.name = name;
            this.age = age;
            this.parti = function()
            {
                document.writeln("名字是:" + this.name + "<br>");
                document.writeln("年纪是:" + this.age + "<br>");
            };
        }
        var p = new Student('jeri', 3);
        document.writeln("typeof p is " + typeof(p));
        //typeof(p) is object
        p.parti();
        p.age = 4;
        p.parti();
        /*the following two methods can also access some properties.*/
        document.writeln("" + p["age"]);
        document.writeln("" + p["a" + "ge"]);


        if (p instanceof Student) document.writeln("p是Student的实例<br>");
        /*javascript 中的对象全部是Object 的子类
        Because this object is the topmost parent object in the prototype inheritance hierarchy, all other object classes inherit its methods and properties. It's a close enough call that JavaScript 2.0 may well move it into the class-based object-oriented category at which time the prototype inheritance would be replaced with super-class/sub-class mechanisms and the arguments become null and void.  */
        /*When the Global object is created, it always has at least the following properties:
           Object object
           Function object
           Array object
           String object
           Boolean object
           Number object
           Date object
           Math object
           Value properties
       */
        if (p instanceof Object) document.writeln("p是Object的实例");
    </script>

    文章转载自:https://blog.csdn.net/qq_44594249/article/details/100032253

  • 相关阅读:
    推荐一个JavaScript触发器插件,可通过指定频次、指定时间内触发指定的处理函数
    TortoiseGit for windows安装与配置
    Postgresql 迁移随笔一
    三边定位 c#
    unset变量释放内存不起作用
    局域网下 连接别人的数据库授权
    iconv 参数详解
    urlencode()和rawurlencode()区别
    php数组函数
    php://input和parse_str()使用
  • 原文地址:https://www.cnblogs.com/renzhe111/p/12176683.html
Copyright © 2011-2022 走看看