那幾個函數的應用:
<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>