那几个函数的应用:
<script>
//全局变量删不掉,而全局属性能删掉
var a=123;
function aa () {
b=321;
delete b;
}
aa();
delete a;
//console.log(a);
var str="wo ai sanmei";
/*构造函数模式*/
function strobj (argument) {
this.concats=function (argument) {
arguments[0].concat(arguments[1]);
console.log(arguments[1].concat(arguments[0]));
};
this.indexOfs=function (argument) {
console.log(arguments[0].indexOf("o"));
};
this.lastIndexOfs=function (argument) {
console.log(arguments[0].indexOf("o"));
};
this.trims=function (argument) {
console.log(arguments[0].trim().length);
};
this.touppers=function (argument) {
console.log(arguments[0].toUpperCase());
};
this.toLowers=function (argument) {
console.log(arguments[0].toLowerCase());
};
}
strobj.prototype.slices = function(argument) {
console.log(arguments[0].slice(0,5));
};
strobj.prototype.substrs = function(first_argument) {
console.log(arguments[0].substr(0,4));
};
strobj.prototype.substrings = function(first_argument) {
console.log(arguments[0].substring(0,6));
};
/*String*/
//charAt() charCodeAt()
console.log(str.charAt(0));
console.log(str.charCodeAt(0));
//字符串的连接 concat(),更多情况下用加号更方便
var str1='lio';
var li=new strobj();
//concat连接
li.concats(str,str1);
//slice剪切
li.slices(str);
//substr从第几个选几个
li.substrs(str);
//substring从第几个到底几个
li.substrings(str);
//indexOf字符位置
li.indexOfs(str);
//lastIndexOf
li.lastIndexOfs(str);
//trim 删除空格
li.trims(" Lio ai sanmei ");
//大小写转换
li.touppers(str);
li.toLowers(str);
//字符串匹配
</script>