zoukankan      html  css  js  c++  java
  • 当JS面向对象之后

    我把JS也面向对象了,感兴趣的朋友可以来看看代码,哈哈:

    <script>
            function zzl() {//一个类
                getname = function () { //在本类内部访问,私有方法
                    return "zhangzhanling";
                }
                this.getfirstname = function () { //在本类及本类的实例中访问,公用方法
                    return "zhang";
                }
                this.getfirstAndFullName = function () {
                    return "full:" + getname() + ",firstName:" + this.getfirstname();
                }
     
            }
            zzl.prototype.hello = function () { //公有方法,它的实例可以访问
                return "hello";
            }
            zzl.info = function () { //公有的静态方法,直接可以访问
                return "1.1.1";
            }
            zzl.prototype.info = {//公有扩展对象
                born: {//扩展属性
                    yanli: "1983-03-18",
                    yinli: "1982-12-05"
                },
                printBorn: function () {//扩展方法
                    alert("生日");
                }
            }
            var z = new zzl(); //建立zzl的一个实例
            alert(z.getfirstAndFullName());
            z.info.printBorn();
            alert(z.info.born.yanli);
           
        </script>
  • 相关阅读:
    ajax长轮询实现即时聊天室
    node.js 通过post上传图片并显示
    Java集合类详解
    多行子查询
    Oracle中查看用户下面所有表的语句
    关于Oracle的create
    Oracle数据库学习
    oracle数据库
    js 中 undefined、NaN、null
    学习数据库SQL语句2
  • 原文地址:https://www.cnblogs.com/lori/p/2099857.html
Copyright © 2011-2022 走看看