zoukankan      html  css  js  c++  java
  • 创建对象的方式

    构造器方式

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    </body>
    <script type="text/javascript">
        function Person(name,age){
            this.name=name;
            this.age=age;
            this.eat=function(){
                alert("eat"+name+age);
            }
        }
        var person=new Person("ton",1);
        person.eat();
    </script>
    </html>
    View Code

    json方式

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    </body>
    <script type="text/javascript">
        var person={
                name:"tom",
                age:21,
                eat:function(){
                    alert("ok"+person.age)
                }
                
        }
        alert(person.name)
        alert(person.age)
        person.eat();
    </script>
    </html>
    View Code
  • 相关阅读:
    FreeNAS的安装使用记录
    slackware中配置命令行下的分辨率
    创建类的理由
    软件开发人员的入门级书单
    Pow(x, n)
    Group Anagrams
    Rotate Image
    Permutations
    Multiply Strings
    Combination Sum II
  • 原文地址:https://www.cnblogs.com/javaweb2/p/6263645.html
Copyright © 2011-2022 走看看