代码之家  ›  专栏  ›  技术社区  ›  Web_Designer

Javascript使用逐位或等于运算符|=创建polyfill?

  •  -1
  • Web_Designer  · 技术社区  · 12 年前

    使用创建polyfill有什么问题吗 JavaScript's bitwise 1 或等于运算符 |= ?

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


    1 Bitwise operator reference
    2 Date.now() reference

    1 回复  |  直到 12 年前
        1
  •  7
  •   Niet the Dark Absol    12 年前

    嗯,是吗?两者之间有很大区别 | || ,和polyfill应使用:

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

    毕竟,如果你使用这个:

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

    你会得到结果的 0 覆盖函数。