如果第二个参数 bUnicode255For1 === true,则所有字符长度为 1
否则如果字符 Unicode 编码 > 255 则长度为 2
<script type="text/javascript"> function strLength(s, bUnicode255For1) { let len = s.length if (bUnicode255For1) return len for (const i of s) { if (i.charCodeAt(0) > 255) { len++ } } return len } </script>