代码之家  ›  专栏  ›  技术社区  ›  Eugene Yarmash

为什么这个表达式返回真值[[副本]

  •  8
  • Eugene Yarmash  · 技术社区  · 15 年前


    Can somebody explain this Javascript method ?

    (x = [].reverse)() === window // true
    

    知道为什么吗?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Andy E    15 年前

    (x=[].reverse)() === window // true

    一开始我不理解这个,但我想这很简单:首先x变成数组的反函数,然后用 this === window . 所以它等于 window.reverse() . 只要查一下,reverse()就可以正常工作了,所以 window.reverse() === window -尽管它可能与以前不同。

    我从这个链接得到这个答案

    http://news.ycombinator.com/item?id=1122004