javascript - "TypeError: object is not a function"

标签 javascript node.js ecmascript-harmony co

我不知道这是从哪里来的,安装了 4.0 版本的 CO 和 0.11.14 版本的 Node.js。非常简单的代码,适用于 3.1(只是注意到以前版本的 co 有所不同)

"use strict"
const co = require('co')

const main = function*() {
    console.log('THIS IS LOGGED')
}

co(main)()

给我这个输出:

/home/tbrown/.nvm/current/bin/node --debug-brk=23342 --nolazy
--harmony routes-to-apache-reverse-proxy.js Debugger listening on port 23342 THIS IS LOGGED /home/Documents/projects/server/routes/routes-to-apache-reverse-proxy.js:8 co(main)()
        ^ TypeError: object is not a function
    at Object.<anonymous> (/home/Documents/projects/server/routes/routes-to-apache-reverse-proxy.js:8:9)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.runMain [as _onTimeout] (module.js:501:10)
    at Timer.listOnTimeout (timers.js:133:15)

Process finished 

with exit code 1

它引用的行是

co(main)()

最佳答案

OK CO 从 3 更改为 4 - 这看起来是等效的

"use strict"
const co = require('co')

const main = function*() {
    console.log('THIS IS LOGGED')
}

co(main).
    catch(function(e){
        console.error(e)
    })

关于javascript - "TypeError: object is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27156841/

相关文章:

javascript - 错误 : cannot find module when testing with mocha

node.js - 如何在带有 typescript 项目的 react js 中使用 .env 文件?

javascript - ECMAScript 6 和 ECMAScript Harmony 有什么区别?

javascript - 遍历范围的函数式方法 (ES6/7)

javascript - 作为对象传递给父级的值

javascript - Vue.js : How to use id to select an item in another array

node.js - 如何在KeystoneJS中上传S3文件

javascript - 使用 ES6/Harmony 以 FP 方式创建具有相同值和键的映射

javascript - 脚本无法处理简单的算术

javascript - 在 jQuery 中检查数组中的元素是否为空