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>
  • 相关阅读:
    Redis学习之(一)
    SpringMVC之学习(0)
    Node.js之Express三
    Node.js之Express二
    Node.js之Express一
    Node.js进程管理之进程集群
    Node.js进程管理之子进程
    Node.js其他模块
    Node.js进程管理之Process模块
    Node.js HTTP Server对象及GET、POST请求
  • 原文地址:https://www.cnblogs.com/lori/p/2099857.html
Copyright © 2011-2022 走看看