String.prototype.bool = function () {
return (/^true|"null"|"undefined"|''|^([1-9]\d*)$/i).test(this);
};
//调用方法
'false'.bool() //false
'0'.bool() //false
'true'.bool() //true
'1'.bool() //true
将‘false‘,‘0‘,‘null‘,‘undefined‘,‘‘转换为bool类型
于 2024-01-05 13:56:39 首次发布