">>="是什么意思?"

4

我不明白 >>= 是什么意思(我以为大于或等于是 >=),还有下面的 (times & 1) 是什么。

function repeat (string, times) {
var result = ''
while (times > 0) {
if (times & 1) result += string
times >>= 1
string += string
}
 return result
}

看起来这是一个位运算符,但我不明白为什么有个=在那里... 这甚至让我感到困惑。 - Zizouz212
请看这里 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators 一个非常有用的资源。 - Dinesh
times >>=1 是一种简写方式,与 times = times >> 1 相同。类似于 a += b (a = a + b) 的语法。 - user1375096
3
这个问题的标题不太具体描述。 - 425nesp
这需要很多的努力,而 function repeat(string,times) {return new Array(times+1).join(string);} 就足够了... - Niet the Dark Absol
1个回答

5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接