<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>你不知道的javascript(中卷)</title>
</head>
<body>
<script type="text/javascript">
/*
//9、语法:句子和表达式的区别
var a = 3*6;// 3*6是表达式,
var b = a; //a也是表达式,
b;//b是表达式,
//三个独立的句子都是句子
*/
/* //9、apply
var a = Array.apply(null,[1,2,3]);//第二个参数是数组
var c = 1;
var d = 2;
var e = 3;
var b = Array.call(null,c,d,e);//第二个参数开始是变量
console.log(a);//[1,2,3]
console.log(b);//[1,2,3]*/
/*
//8、原生数组作为构造函数
var a = new Array(4);
var b = new Array(1,2);
console.log(a.length);
console.log(b.length);
console.log(a);
console.log(b);*/
/* //7、对象的包装与解封
//封装对象包装
var a = new Boolean(false);
if(!a){
console.log("!a 为true")//没有输出,因为不会执行道这里,new 的a为一个对象不是布尔值,所以!a都是false
}
else{
console.log("!a 为false"); //
}
//封装对象解释
var s1 = new String("abc");
var s2 = s1+"";
var s3 = Object(s1);
console.log(typeof(s1));// object
console.log(typeof(s2));// string
console.log(typeof(s3));// object
//拆装
var s = new String("123");
var n = new Number(123);
var b = new Boolean(true);
console.log(s.valueOf());//"123"
console.log(n.valueOf());//123
console.log(b.valueOf());//true
*/
/*
// 6、new的字符和tostring的串比较
var s1 = new String("Hello world!");
var s2 = s1.toString();
console.log(s1==s2); //true 只比较值
console.log(s1===s2); // false 比较两个对象是否完全一致,当指向通一个对象的时候为true'*/
/* 5、赋值与引用
var a = 1;
var b = a;
a++;
console.log(a);//2
console.log(b);//1
var arr = [1,2,3];
var arr1 = arr;
arr.push(4);
console.log(arr);//[1,2,3,4]
console.log(arr1);//[1,2,3,4]
//静态的变量是通过值来传递的,可变的对象是通过引用来传递的,*/
/*
//4、js数值类型
//js 数值类型,没有真正意义的整形,
console.log(43===43.0); //true
var a = 323.32323;
console.log(a.toFixed(2)) // 保留两位小数
console.log(a.toPrecision(2))保留两位有效数字
console.log(43..toFixed(3));// 第一个.是数值的小数点
console.log(parseInt(1.2)); //直接取整数部分
console.log(parseInt(1.5));
console.log(parseInt(1.6));
console.log(Number.isInteger(43.0))//true
*/
/*
//3、数组和字符串的区别
var a = "abc";
a[0] = "z";
console.log(a); //abc
var b = ["a","b","c"];
b[0] = "z";
console.log(b); //["z","b","c"]
console.log(a.charAt(0));
//数组可以通过下标修改改下标对应的值,但是字符串不可以
*/
/*
//2、闭包
function foo(){
var a = 2;
function bar(){
console.log(a)
}
return bar;
}
var baz = foo();
console.log(baz);
//baz();
*/
/*
//1、正则
var str = 'width : 100px ;';// width: r(100px);
var reg = /(\w+)(\s*)(?::)\2(\d+(?:px))\2;$/;
console.log(str.replace(reg,"$1:r($3);"));
*/
/*var s = "二个如果43543gergreg";
var reg = /^[\u4e00-\u9fa5]$/;
console.log(s.match(s,"\u4e00-\u9fa5"));
*/
</script>
</body>
</html>