小编Kiw*_*Lau的帖子

使用蓝鸟作为猫鼬,得到“ .bind不是函数”

我用蓝鸟猫鼬

const Promise = require("bluebird");
const mongoose = require("mongoose");
mongoose.Promise = Promise;
Run Code Online (Sandbox Code Playgroud)

我想使用Promise.bind在诺言链中共享变量:

function getAutherOfBook(name)
{
    return Book.findOne(
        {
            name: name
        }, "-_id auther")
        .then(doc =>
        {
            return doc.auther;
        });
};


function geNationalityOfAuther(name)
{
    return Auther.findOne(
        {
            name: name
        }, "-_id nationality")
        .then(doc =>
        {
            return doc.nationality;
        });
};


getAutherOfBook("The Kite Runner")
    .bind({})
    .then(auther =>
    {
        this.auther = auther;
        return geNationalityOfAuther(auther);
    })
    .then(nationality =>
    {
        console.log("auther: ", this.auther);
        console.log("nationality: ", nationality);
    })
    .bind()
Run Code Online (Sandbox Code Playgroud)

但是我得到了错误: …

mongodb node.js bluebird

1
推荐指数
1
解决办法
386
查看次数

标签 统计

bluebird ×1

mongodb ×1

node.js ×1