문제

Is there anything wrong with creating polyfills using JavaScript's bitwise1 or equals operator |=?

Date.now |= function() {
    return +new Date;
};


1Bitwise operator reference
2Date.now() reference

도움이 되었습니까?

해결책

Um, yes? There's a major difference between | and ||, and polyfills should use:

Date.now = Date.now || function() {return +new Date;};

After all, if you used this:

Date.now = Date.now | function() {return +new Date;};

You'd get the result 0 overwriting the function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top