Why do two regex literals in my Javascript vary on a property?

后端 未结 2 1913
后悔当初
后悔当初 2021-01-07 06:47

I read in Javascript: The Good Parts by Douglas Crockford that javascript regular expression literals share the same object. If so, then how come these two regex li

2条回答
  •  情书的邮戳
    2021-01-07 07:34

    Because they are different objects.

    document.write(a === b);
    

    Even this outputs false.

    Either Crockford was wrong, or he was right at the time but times have changed.

    I realize this isn't a particularly helpful or informative answer; I'm just pushing back on what I perceive as your disbelief that something Crockford wrote could be (now) false.

    Do you have a reference to that claim, by the way? Would be interesting to read it in context (I don't have the book).

提交回复
热议问题