简体   繁体   English

我的代码破坏了jsbin和repl.it?

[英]My code broke jsbin and repl.it?

while (re)doing this tutorial, http://reactivex.io/learnrx/ , I find that both repl.it and jsbin.com reject functional javascript like this. 在(重新)执行本教程http://reactivex.io/learnrx/时 ,我发现repl.it和jsbin.com都拒绝像这样的功能性javascript。

movieLists.
        concatMap(function(category) {
            return category.videos.map(function(video){

                return video.boxarts
                    .reduce(function(acc,cur){
                        return (acc.width*acc.height)<(cur.width*cur.height) ? acc:cur
                    }).map(function(boxart){
                        return {id:video.id, title:video.title}
                    });


            })
        })

results in 结果是

"TypeError: video.boxarts.reduce(...).map is not a function
    at dihuwo.js:105:24
    at Array.map (native)
    at dihuwo.js:100:36
    at dihuwo.js:24:14
    at Array.map (native)
    at Array.concatMap (dihuwo.js:18:3)
    at dihuwo.js:99:3
    at dihuwo.js:113:3
    at https://static.jsbin.com/js/prod/runner-3.35.5.min.js:1:13616
    at https://static.jsbin.com/js/prod/runner-3.35.5.min.js:1:10537"

why does the code here on jsbin fail, while the repl here accepts it as legit? 为什么jsbin上的代码会失败,而此处的repl 却将其视为合法?

What silly thing am I missing? 我想念什么傻事? I repeat... the code is passing on the tutorial page. 我再说一遍...代码正在教程页面上传递。 It's just impossible so far to test on any other repl. 到目前为止,不可能对任何其他repl进行测试。

PS All helper functions, such as concatMap, are defined above this code, so that's not the problem. PS所有帮助程序功能(例如concatMap)均在此代码上方定义,因此这不是问题。

It does not work because in that tutorial they override Array.prototype.reduce . 它不起作用,因为在该教程中它们覆盖了Array.prototype.reduce

Their implementation works differently to the standard one and it always returns an array. 它们的实现与标准实现不同,并且总是返回一个数组。

Generally it's a bad practice to do so and must be avoided. 通常,这样做是不好的做法,必须避免。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM