• 第五天:内置对象(7.Javascript内置对象)


    1)中所术是内置对象,2)中为自定义对象

    代码说明如下

    2.1.1 定义并创建对象实例方式1,代码如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>对象</title>
    </head>
    <body>
    <script>
    people= new Object();
    people.name="iwen";
    people.age="30";
    document.write("name:"+people.name+";age:"+people.age);
    </script>
    </body>
    </html>

    运行结果:

    2.1.2 定义并创建对象实例方式2,代码如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>对象</title>
    </head>
    <body>
    <script>
    people={name:"lucy",age:"32"};
    document.write("name:"+people.name+";age:"+people.age);
    </script>
    </body>
    </html>

    运行结果:

    2.2 使用函数来创建对象,然后创建新的对象实例

    代码如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>对象</title>
    </head>
    <body>
    <script>
    function people(name,age){
    this._name=name;
    this._age=age;
    }
    son=new people("LiLei","10");
    document.write("name:"+son._name+";age:"+son._age);

    </script>
    </body>
    </html>

    运行结果:

    犯过的错误:

    son = new people("lily",20);

    写成了 son = people("lily",20);

  • 相关阅读:
    穷举 迭代 while
    for 循环
    switch case
    if else 语句
    数据类型
    语句的输入、输出
    控件——DataGridview
    mysql-bin.000001文件的来源及处理方法
    /var/log目录下的20个Linux日志文件功能详解
    CountDownLatch
  • 原文地址:https://www.cnblogs.com/fenr9/p/5621480.html
Copyright © 2020-2023  润新知