>>> (Zero-fill right shift) Elaboration [duplicate]
Possible Duplicate:
What good does zero-fill bit-shifting by 0 do? (a >>> 0)
I was looking at array.indexOf()
, and I'm aware that IE7 does not natively support that. I was reading the MDC and saw their example of how to prototype it into browsers that don't support it. I'm reading through it trying to under开发者_StackOverflowstand how everything works, but I'm not sure I'm understanding it 100%. The main cause for confusion is the bitwise operators, specifically >>>
. I'm not sure what this operator is useful for. Below is the way that they're using it. Can anyone explain exactly what it's useful for and why you can't just if (t.length === 0)
?
var t = Object(this);
var len = t.length >>> 0;
if (len === 0)
return -1;
It allows indexOf
to be called on array-like objects that might have weird length
properties.
For example:
var fakeArray = { length: -3, '0': true, '1': false, '2': null };
精彩评论