Array.push return pushed value?

前端 未结 6 1904
盖世英雄少女心
盖世英雄少女心 2021-01-04 02:30

Are there any substantial reasons why modifying Array.push() to return the object pushed rather than the length of the new array might be a bad idea?

I

6条回答
  •  别那么骄傲
    2021-01-04 03:07

    Just as a historical note -- There was an older version of JavaScript -- JavaScript version 1.2 -- that handled a number of array functions quite differently.

    In particular to this question, Array.push did return the item, not the length of the array.

    That said, 1.2 has been not been used for decades now -- but some very old references might still refer to this behavior.

    http://web.archive.org/web/20010408055419/developer.netscape.com/docs/manuals/communicator/jsguide/js1_2.htm

提交回复
热议问题