<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
//为毛现在看书都直接看代码了,看文字总觉的越看越晕。。
//JS高级第五章,引用类型
//string;
Object.prototype.toString
Object.prototype.toLocalString
Object.prototype.valueOf
//三个的区别是神马‘
[1,2,5,5
].toString()
[1,2,5,5
].toLocalString();
//的字符串化是调用 arr[i]的对应函数
var arr = [1,2,4,5
];
/*
function fn(){};
var a = arr.every(fn(e,i,arr){console.log(1)}); //如果每一个都返回true,结果为true
var a = arr.some(fn(e,i,arr){console.log(1)}); //主要一个为true,结果就是ture
var a = arr.forEach
var a = arr.map;
var a = arr.filter(fn(e,i,arr){});
*/
//Data
//RegExp;
var re =
null,
i;
for(i=0; i<10; i++
){
re = /cat/
g;
re.test("catastrophe");
// 就输出一个,后面的没有哦
};
for(i=0; i<10; i++
){
re =
new RegExp("cat","g"
);
re.test("catastrophe")
//每一次都是重新输出正则结果
};
// exec方法会 如果有“g”记录上一次查询到的结果到index属性下面,没有“g”配置都是重新查询
// JS模板 引擎 不解释,嘻嘻~.*;
String
var s = "abcdfg"
;
s.charAt(0
);
s.charCodeAt(0);
// 这个是返回字符串编码
s.slice(1,2
);
s.substr(1,2);
//2个长度
s.substr(1,2)
// 长度到2
s.encodeURI();
s.encodeURIComponent();
Function;
function sum(num1, num2){
return num1 +
num2;
};
console.log( sum(1,2
) );
var anotherSum =
sum;
console.log( anotherSum(1,10
) );
sum =
null;
console.log( anotherSum(1,10) )
// 11 ,这个是引用指针的,不要忘记了
function htmlEscape(text){
return text.replace(/[<>"&]/g,
function(match, pos, originalText){
switch(match){
case "<"
:
return "<"
;
case ">"
:
return ">"
case "&"
:
return "&"
case "\""
:
return """
}
});
};
</script>
</body>
</html>
转载于:https://www.cnblogs.com/diligenceday/p/3488365.html