zoukankan      html  css  js  c++  java
  • JavaScript 中“类”的简单备忘

    JavaScript 中“类”的实现,体现Object Oriented思想,供初学者备忘。

    <head runat="server">

        <title></title>

        <script type="text/javascript">

        // 定义类  

        function MyClass(name, age) {
                this.name = name;
                this.age = age;
        }
        MyClass.prototype =
        {
            name: String , //变量
            age: Number,
            show: function() {   //方法
                alert("the name is "+ this.name);
            },

            test: function() {
                alert("the age is "+ this.age);
            }
        }

       // 使用类

        function MyGet() {

            var myInstance = new MyClass("Sophie", 4);
            testPassParam(myInstance );

        }
        // 类为参数
        function testPassParam(param) {
            param.show();
            param.test();
        }
         
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <input id ="btn" type="button" value="click me" onclick="MyGet()" />
        
        </div>
        </form>
    </body>
    </html>
  • 相关阅读:
    name mangling
    Haskell: What is Weak Head Normal Form
    取模运算和取余运算的区别
    a common method to rotate the image
    代码静态分析工具
    LeeCode-Single Number III
    七夕这天
    mysql TO_DAYS()
    (转)剖析Linux文件编码的查看及修改
    docker
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/1425386.html
Copyright © 2011-2022 走看看