读书人

prototype的解读之判断string是不是为

发布时间: 2012-07-01 13:15:00 作者: rapoo

prototype的解读之判断string是否为空

1blank()

?

原api的用途

?

?? Check if the string is 'blank',meaning either empty or containing only whitespace.

?

?? 判断这个string是不是空的---意味着空或者值含有空白字符(空格)

?

?

用例

?

''.blank();  // true'  '.blank();   //true' a  d '.blank();  //false
?

?

源码展示:

?

?

blank:function(){  return /^\s*$/.test(this);}
?

?

?

2、empty()

?

原api的用途

?

?? Checks if the string is empty.

?

?? ?检测string是否为空

?

用例:

?

?

''.empty();   //true'  '.empty();  //false' ad  '.empty();  //false
?

源码展示:

?

?

empty:function(){   return this == '';}

?

?

总结一下:

?

blankempty的api在判断如空格这样的空白字符的时候是返回true的

?

读书人网 >Web前端

热点推荐