zoukankan      html  css  js  c++  java
  • 第五天:内置对象(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);

  • 相关阅读:
    3.09课·········打印矩形,三角形和菱形
    3.09课·········for穷举和迭代
    3.09课·········for循环
    Django的中间件
    Cookie和Session
    Django之ORM
    Django ORM那些相关操作
    Django form表单
    Django model 中的 class Meta 详解
    pymysql模块的使用
  • 原文地址:https://www.cnblogs.com/fenr9/p/5621480.html
Copyright © 2011-2022 走看看