zoukankan      html  css  js  c++  java
  • JavaScript学习笔记(04对象和内置对象-P69-P83)

    两种创建对象方式:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <script>
            /*-----------方式一①-----------*/
            //people = new Object();
            //people.name = "Lee";
            //people.age = 27;
            /*-----------方式一②-----------*/
            //people = { name: "Ski", age: 26 };
    
            /*-----------方式二(函数定义对象)-----------*/
            function peopleFun(name, age) {
                this.name = name;
                this.age = age;
            }
            people =new peopleFun("Lee.Ski", 26.5);
            people2 = new peopleFun("Lee.SkII", 27);
            document.write("name:" + people.name + ",age:" + people.age);
            document.write("name:" + people2.name + ",age:" + people2.age);
        </script>
    </body>
    </html>
    View Code

    内置对象一般会提供已经定义好的属性和方法使用:

    示例代码:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <script>
            var str = "Hello world";
            //document.write(str.length);
            //document.write(str.indexOf("world"));
            //document.write(str.match("world"));//匹配到了则返回world,否则返回null
            //document.write(str.replace("world","Ski"));
            //document.write(str.toLowerCase());
            var str1 = "1,2,3,4,5,6";
            //document.write(str1.split(","));
            var strArr = str1.split(",");
            for (var i = 0; i < strArr.length; i++) {
                document.write(strArr[i]+"<br/>");
            }
        </script>
    </body>
    </html>
    View Code

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <script>
            var arr1 = ["happy", "time", "bir"];
            var arr2 = [6, 20, 0.3, 4, 5];
            //document.write(arr1.concat(arr2));
            //document.write(arr2.sort((a, b) => a - b));
            //document.write(arr1.push("TT"));
            document.write(arr1.reverse());
        </script>
    </body>
    </html>
    View Code

    End

  • 相关阅读:
    工作流二次开发之新增表单实践(二)
    layui表格及工作流二次开发实践(一)
    记一个递归封装树形结构
    SpringCloud微服务之宏观了解
    统一结果返回&统一异常处理
    mybatis-Plus 实践篇之CRUD操作
    修改MariaDB-root密码
    iftop-监控服务器实时带宽情况
    Wordpress安装-报错说明
    MariaDB忘记root密码
  • 原文地址:https://www.cnblogs.com/LeeSki/p/12284764.html
Copyright © 2011-2022 走看看