🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # 每日英语 1. `compare` 对比(beyond compare 代码对比软件) 2. `Fn` function 缩写 3. `interchange` 交换(交叉, 替换) 4. `standard` 标准 5. `information` 信息 6. `info` information 缩写 7. `code` 代码 8. `coding` 敲代码 9. `ASCII` 美国信息交换标准代码 10. `parse` 分析, 描述 11. `Integer` 整数 12. `Float` 浮点数, 也叫小数 # 关于 arr.sort() ## 函数加括号和不加括号的区别(Fn()和 Fn 的区别) ## 加括号, 直接运行, 如果有返回值, 会接收返回值 ```javascript /****************** start coding... *******************/ function helloWorld() { console.log("hello world!!!"); } helloWorld(); /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ function helloWorld() { return "hello world!!!"; } console.log(helloWorld()); /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ function helloWorld() { return "hello world!!!"; } var res = helloWorld(); console.log(res); /****************** end of coding... *******************/ ``` ## 匿名函数, 现写现用, 不需要复用, 也不用命名 ```javascript /****************** start coding... *******************/ var arr = [5, 3, 2, 1, 2]; // function sortNumber(a,b){ // return a-b; // } console.log( arr.sort(function(a, b) { return a - b; }) ); /****************** end of coding... *******************/ ``` ## 为匿名函数起名字 ```javascript /****************** start coding... *******************/ var helloWorld = function() { return "hello world!!!"; }; var res = helloWorld(); console.log(res); /****************** end of coding... *******************/ ``` ## ES5 支持 function 作为变量传给另一个函数 ```javascript /****************** start coding... *******************/ var arr = [5, 3, 2, 1, 2]; // function sortNumber(a,b){ // return a-b; // } console.log( arr.sort(function(a, b) { return a - b; }) ); /****************** end of coding... *******************/ ``` # 如何声明一个对象 ```javascript /****************** start coding... *******************/ var obj = {}; // 声明一个对象 var obj1 = new Object(); // 声明一个对象 var arr = []; // 声明一个数组 var arr1 = new Array(); // 声明一个数组 /****************** end of coding... *******************/ ``` # 如何给对象的属性赋值 ```javascript /****************** start coding... *******************/ var obj = {}; // 声明一个对象 obj.userName = "xujunhao"; // userName属性值为"xujunhao" console.log(obj); // { userName: 'xujunhao' } obj.sex = "male"; // 性别男 console.log(obj); // { userName: 'xujunhao', sex: 'male' } /****************** end of coding... *******************/ ``` # 对象的属性和方法 对象的属性==>变量 对象的方法==>函数(对象的属性也可以是一个对象) ```javascript /****************** start coding... *******************/ var obj = {}; // 声明一个对象 obj.userName = "xujunhao"; // userName属性值为"xujunhao" console.log(obj); // { userName: 'xujunhao' } obj.sex = "male"; // 性别男 console.log(obj); // { userName: 'xujunhao', sex: 'male' } // 对象的属性也可以是一个对象 obj.school = { schoolName: "MIT", schoolAddr: "USA" }; // { userName: 'xujunhao', // sex: 'male', // school: { schoolName: 'MIT', schoolAddr: 'USA' } // } console.log(obj); /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ var obj = {}; // 声明一个对象 obj.userName = "xujunhao"; // userName属性值为"xujunhao" console.log(obj); // { userName: 'xujunhao' } obj.sex = "male"; // 性别男 console.log(obj); // { userName: 'xujunhao', sex: 'male' } // 对象的属性也可以是一个对象 obj.school = { schoolName: "MIT", schoolAddr: "USA" }; // { userName: 'xujunhao', // sex: 'male', // school: { schoolName: 'MIT', schoolAddr: 'USA' } // } console.log(obj); var obj1 = { sex: "female", addr: "zhengzhou" }; obj.newobj = obj1; // { userName: 'xujunhao', // sex: 'male', // school: { schoolName: 'MIT', schoolAddr: 'USA' }, // newobj: { sex: 'female', addr: 'zhengzhou' } // } console.log(obj); /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ var obj = { eatFood: function() { return "I am eating food !"; } }; // 声明一个对象 var eatRes = obj.eatFood(); console.log(eatRes); // I am eating food ! /****************** end of coding... *******************/ ``` 为对象的方法赋值 ```javascript /****************** start coding... *******************/ var obj = { eatFood: function() { return "I am eating food !"; } }; // 声明一个对象 var eatRes = obj.eatFood(); console.log(eatRes); // I am eating food ! /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ var obj = { eatFood: function() { return "I am eating food !"; } }; // 声明一个对象 var eatRes = obj.eatFood(); console.log(eatRes); // I am eating food ! // 获取校训 function getSchoolMotto() { return "ADIDAS"; // all day I dream about study } obj.getMotto = getSchoolMotto; console.log(obj.getMotto()); // ADIDAS /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ var obj = { eatFood: function() { return "I am eating food !"; } }; // 声明一个对象 var eatRes = obj.eatFood(); console.log(eatRes); // I am eating food ! // 获取校训 function getSchoolMotto() { return "ADIDAS"; // all day I dream about study } obj.getMotto = getSchoolMotto(); // 返回值 "ADIDAS" console.log(obj.getMotto); // ADIDAS console.log(typeof obj.getMotto); // string /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ var obj = { eatFood: function() { return "I am eating food !"; } }; // 声明一个对象 var eatRes = obj.eatFood(); console.log(eatRes); // I am eating food ! // 获取校训 function getSchoolMotto() { return "ADIDAS"; // all day I dream about study } obj.getMotto = getSchoolMotto(); // "adidas" console.log(obj.getMotto()); // is not a function /****************** end of coding... *******************/ ``` ```javascript /****************** start coding... *******************/ var obj = { eatFood: function() { return "I am eating food !"; } }; // 声明一个对象 var eatRes = obj.eatFood(); console.log(eatRes); // I am eating food ! // 获取校训 function getSchoolMotto() { return "ADIDAS"; // all day I dream about study } obj.getMotto = getSchoolMotto; // "adidas" console.log(obj.getMotto()); // "adidas" console.log(typeof obj.getMotto); // function console.log(typeof obj.getMotto()); // string /****************** end of coding... *******************/ ``` # 多维度数组 ## 什么是多维数组 > 以数组作为元素的数组 ```javascript var arr = []; arr[0] = []; arr[1] = []; console.log(arr); // [ [], [] ] console.log(arr.length); // 2 只看元素个数 ``` ``` var arr = [[],[]]; console.log(arr); // [ [], [] ] console.log(arr.length); // 2 只看元素个数 ``` ## 三维数组 ```javascript var arr = [[[], []]]; console.log(arr); // [ [ [], [] ] ] console.log(arr.length); // 1 ``` ## 五位数组 ```javascript var arr = [[[[[]]]]]; console.log(arr); // 5维数组 console.log(arr.length); // 1 ``` ```javascript // 下标可以写多个 var arr = [[[[["hello world"]]]]]; console.log(arr[0][0][0][0][0]); // hello world ``` # 数据类型转换 ## 强制数据类型转换 ```javascript var a = 1; var b = 2; console.log(a + b); // 3 var c = "hello"; var d = "world"; console.log(c + " " + d); // hello world(字符串连接符) ``` ## 转整数 ```javascript console.log(parseInt("123")); // 123 console.log(parseInt("-123")); // -123 console.log(parseInt("+123")); // 123 console.log(parseInt("123.00")); // 123 console.log(parseInt("123元")); // 123 console.log(parseInt("hello333")); // NaN not a number console.log(parseInt("")); // NaN not a number console.log(parseInt("123.11元")); // 123 console.log(parseInt("helloworld")); // NaN not a number console.log(parseInt([])); // NaN console.log(parseInt(["1"])); // 1 console.log(parseInt(["1", "2", "3"])); // 1 console.log(parseInt("AA")); // NaN console.log(parseInt("AA", 16)); // 170 , 第二个参数表示进制 console.log(parseInt("10", 8)); // 8 console.log(parseInt("10", 2)); // 2 console.log(parseInt("10", 10)); // 10 ```