Weird output of [97,98].map(String.fromCharCode)

后端 未结 2 1640
清歌不尽
清歌不尽 2021-01-19 07:01

this works as expected

[97,98].map(function(x){String.fromCharCode(x)})
// [ \'a\', \'b\' ]

but the output is following line is unexpected<

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 07:31

           a2 = [97,98].map(function(x){return String.fromCharCode(x)});
           alert(a2);
           a2 = [97,98].map(String.fromCharCode);
           alert(a2);
    

    both alert "a,b" for Firefox13 on Linux. the first function was missing a return statement.

提交回复
热议问题