03JavaScript程序设计修炼之道 2019-06-06_20-10-17_2019-06-06_21-12-50 对象定义方式:{}、构造;字符串及常用方法;

29object.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 描述一个人的信息
        var name = "along";
        var sex = "M";
        var age = 32;
        //  liwei
        var name  = "liwei";
        var sex2 = "M";
        var age2 = 33;
        console.log(name);
        // 对象  具体的事物或者抽象的事件
        // 对象定义 无序属性的集合
        /*  键值对 直接量
            var obj = {
                k:v,
                k:v
                ...
            }
        */
        var p1 = {
            name:"along", // 属性------特征
            sex: "M",
            age: 32,
            teach: function() { // 方法-----动态
                console.log("hard workiong");
            }
        };
        var p2 = {
            name:"liwei", // 属性------特征
            sex: "M",
            age: 33
        }
        console.log(p1,typeof p1); // object
        console.log(p2);
        // 访问对象的成员 对象.成员
        console.log(p1.age);
        console.log(p1[‘age‘]);
        var k = ‘sex‘;
        console.log(p1[k]); // p1[‘sex‘] p1.k
        p1.teach();

        // 对象可以动态添加属性
        p1.tel = "13988888888";
        console.log(p1);
        p1.sing = function() {
            console.log("along is singing");
        }
        p1.sing(); // window.sing()

        function fn() {

        }

        fn(); // window.fn();
    </script>
</body>
</html>

30object.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 对象的创建方式二 通过new 构造函数 Array String Number Date Function Object...
        var arr = new Array(1,2);
        /* arr也是对象 可以动态添加属性
        arr.index = 10;
        console.log(arr.index);
        */
        /*
        var num = 10;// 基本数据类型 不能添加属性
        num.index = 10;
        console.log(num.index);
        */
        var num = new Number(10);
        num.index = 10;
        console.log(num.index);

        var str = new String("hello");// 字符串对象

        function fn() {

        }
        fn.a = 10;
        console.log(fn.a);
    </script>
</body>
</html>

31object.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var num = 10;
        var num2 = num;// num2 = 10
        num = 20;
        console.log(num2); // 10 

        // 引用类型
        var obj = {name: "along"};
        var obj2 = obj;
        obj.name = "along666";
        console.log(obj2.name);

        var arr = [10,20,30];
        var brr = arr;
        brr[0] = 100;
        console.log(arr[0]);

        // arr [100,20,30]

        function fn(brr) {
            brr[0]--;
        }
        fn(arr);  
        console.log(arr[0]); // 99
    </script>
</body>
</html>

32string.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //
        /*
        var str = "hello";
        var str2 = ‘123‘;
        */
        function fnCharAt() {
            var str = "aBg0hdhadjk123";
            var ch = str.charAt(0); // 返回对应位置的字符
            var code = str.charCodeAt(3);// 返回对应位置的字符编码  a 97  A 65 0 48
            var ch2 = String.fromCharCode(99); // 返回编码对应的字符
            console.log(ch);
            console.log(code);
            console.log(ch2);
        }
        fnCharAt();

        function fnIndexOf() {
            var str = "heillwoer23kk";
            var index = str.lastIndexOf(‘2‘);
            console.log(index);
        }
        fnIndexOf();

        function fnSubstr() {
            var str = "welcome to china";
            var res = str.substr(3);// 从序号3开始 截取到最后
            var res2 = str.substr(3,7);// 从序号3开始 截取7个长度字符
            var res3 = str.substring(3);// // 从序号3开始 截取到最后
            var res4 = str.substring(3,7); // 从序号3开始 截取到序号为7的前一位为止
            var res5 = str.slice(3);// 从序号3开始 截取到最后
            var res6 = str.slice(3,7);// 从序号3开始 截取到序号为7的前一位为止
            console.log(res); // come to china
            console.log(res2);// come to
            console.log(res3); // come to china
            console.log(res4); // come
            console.log(res6);

        }
        fnSubstr();

        function fnSplit() {
            var str = "welcome to china";
            var arr = str.split(" ");
            str = arr.join(" ");
            console.log(arr,str);
            var filename = "1.4.2.txt";
            var res = filename.split(".")
            var extname = res[res.length-1];
            console.log(extname);
            // 1 "http://www.baidu.com?uname=zs&age=22" 如何获取uname和age
            // 2 "abcdefg" => "gfedcba"
        }
        fnSplit()

        function fnReplace() {
            var str = "nnd 大家好 nnd 我是";
            //str = str.replace(‘nnd‘,"***"); // 惰性
            console.log(str.split("nnd"));// ["", " 大。。。"," 我是"]
            str = str.split("nnd").join("*");
            console.log(str);
        }
        fnReplace();

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

原文地址:https://www.cnblogs.com/HiJackykun/p/11141131.html

时间: 2024-11-06 07:13:56

03JavaScript程序设计修炼之道 2019-06-06_20-10-17_2019-06-06_21-12-50 对象定义方式:{}、构造;字符串及常用方法;的相关文章

03JavaScript程序设计修炼之道 2019-05-19_14-33-19--05-19_15-09-07 js简介与基本使用、变量与常量

es.md JavaScript程序设计修炼之道 -前置知识 html5+css3 -课程大纲 1.客户端原生js(es6/es7/..) 2.js常用库 jq等 3.服务端js(node/express/koa) 4.前端js框架(vue/react/..) ... -课程地位 学好js,走遍天下都不怕,是web前端或web全栈开发最重要最核心的技术,直接决定职业收入和发展 客户端原生javascript(es5/es6/es7/...) js简介与基本使用 html 标记语言 css jav

03JavaScript程序设计修炼之道 2019-06-09_fe-js-053Math对象_ Date对象、es6对象新变化

36Date.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatib

03JavaScript程序设计修炼之道-2019-06-18_20-07-52-Dom 文档对象模型

原文地址:https://www.cnblogs.com/HiJackykun/p/11053883.html

03JavaScript程序设计修炼之道-2019-06-20_20-07-53

06changeColor.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-C

03JavaScript程序设计修炼之道 2019-06-23_15-50-11 验证码

1.png tool.js function rand(min,max) { return Math.round(Math.random()*(max-min)+min); } function $(id){ return document.getElementById(id); } 验证码.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/

03JavaScript程序设计修炼之道 2019-06-27_20-04-17 节点元素操作:复制

15clone.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compati

03JavaScript程序设计修炼之道 2019-06-25_20-34-21-2019-06-25_20-44-06 节点元素的操作:增删改

14nodeOper.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Comp

03JavaScript程序设计修炼之道 2019-05-23_20-28-51_2019-05-26_21-12-07 for、练习、hw

16for.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatibl

03JavaScript程序设计修炼之道 2019-06-02_15-20-09 for each 数组es6的方法

25array4.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compat

03JavaScript程序设计修炼之道 2019-06-04_fe-js-044es6解构赋值之数组解构_2019-06-06_20-10-17 解构赋值、数组排序法

27array6.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compat