prototype的解读之判断string是不是为空
prototype的解读之判断string是否为空
1、blank()
原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 == ''; }
总结一下:
- blank比empty的api在判断如空格这样的空白字符的时候是返回true的