标签:style blog color os io java strong ar for
第一章 javascript概述 (略)
第二章 词法结构(略)
第三章 类型,值和变量
1、 全局属性:undefined, Infinity, and NaN
全局函数:isNaN(), parseInt() , and eval()
构造函数:Date(), RegExp(), String(), Object(), and Array()
全局对象:Math and JSON
2、包装对象与临时对象
3、数组复制代码:
var a = [‘a‘, ‘b‘, ‘c‘]; var b = []; for (var i = 0; i < a.length; i++) { b[i] = a[i]; }
4、判断两个数组相等代码:
function equalArrays(a, b) { if (a.length != b.length) return false; for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false; return true; }
5、 JavaScript type conversions (类型转换表)
6、显示转换
Number("3"); // => 3 String(false); // => "false" Or use false.toString() Boolean([]); // => true Object(3); // => new Number(3)
7、隐式转化
x + ""; // Same as String(x) +x; // Same as Number(x). You may also see x-0 !!x; // Same as Boolean(x). Note double !
8、常用的Number方法
var n = 17; binary_string = n.toString(2); // Evaluates to "10001" octal_string = "0" + n.toString(8); // Evaluates to "021" hex_string = "0x" + n.toString(16); // Evaluates to "0x11" var n = 123456.789; n.toFixed(0);// "123457" n.toFixed(2); // "123456.79" n.toFixed(5); // "123456.78900" n.toExponential(1); // "1.2e+5" n.toExponential(3); // "1.235e+5" 有效数字比指定的位数多一位 n.toPrecision(4); // "1.235e+5" 有效数字的位数是否少于数字整数部分的位数 n.toPrecision(7); // "123456.8" n.toPrecision(10);// "123456.7890" parseInt("3 blind mice")// => 3 parseFloat(" 3.14 meters") // => 3.14 parseInt("-12.34") // => -12 parseInt("0xFF") // => 255 parseInt("0xff") // => 255 parseInt("-0XFF") // => -255 parseFloat(".1") // => 0.1 parseInt("0.1")// => 0 parseInt(".1")// => NaN: integers can‘t start with "." parseFloat("$72.47");// => NaN: numbers can‘t start with "$" parseInt("11", 2);// => 3 (1*2 + 1) parseInt("ff", 16);// => 255 (15*16 + 15) parseInt("zz", 36);// => 1295 (35*36 + 35) parseInt("077", 8); // => 63 (7*8 + 7) parseInt("077", 10);// => 77 (7*10 + 7)
9、toString()与valueOf()
({x:1, y:2}).toString() // => "[object Object]"
10、嵌套作用域
var scope = "global scope"; function checkscope() { // A global variable var scope = "local scope"; function nested() { // A local variable var scope = "nested scope"; // A nested scope of local variables return scope; // Return the value in scope here } return nested(); } checkscope();// => "nested scope"
11、变量提前声明,so应该尽量把声明变量放在函数体顶部…………
12 、作用链域、对象列表、变量解析……
第四章 表达式和运算符
标签:style blog color os io java strong ar for
原文地址:http://www.cnblogs.com/liguwe/p/3951008.html