【问题标题】:"TypeError: object is not a function"“类型错误:对象不是函数”
【发布时间】:2015-01-25 05:38:17
【问题描述】:

我不知道这是从哪里来的,安装了 4.0 版的 CO 和 0.11.14 版的 Node。在 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)()

【问题讨论】:

    标签: javascript node.js ecmascript-harmony co


    【解决方案1】:

    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)
        })
    

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      • 2013-04-01
      相关资源
      最近更新 更多