0
私はコールバック関数と約束についていくつかの基本的な作業を行ってきました。しかし、次のコードを見ると、zzzという言葉がどこから来たのか分かりません。mongoose約束とコールバック関数の入力
私は(zzz)がコールバック関数の入力になると思っていました。コールバック関数の中で、zzzは定義されませんでした。
return Dishes.find({}).exec()
は何も返さない実行のみです。それが何かを返すとしても、入力の代わりに(zzz)コールバック関数の出力に行きます。
質問は愚かであるならば、私はちょうど2時間のこの時点で見て...把握することはできません申し訳ありませんおかげ
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const Dishes = require('./models/dishes');
const url = 'mongodb://localhost:27017/conFusion';
const connect = mongoose.connect(url, {
useMongoClient: true
});
connect.then((db) => {
console.log('Connected correctly to server');
var newDish = Dishes({
name: 'Uthappizza',
description: 'test'
});
newDish.save()
.then((zzz) => {
// ??? where did this zzz come from ??????????????????????????????????????????????
console.log(zzz);
return Dishes.find({}).exec();
})
.then((xxx) => {
console.log(xxx);
return db.collection('dishes').drop();
})
.then(() => {
return db.close();
})
.catch((err) => {
console.log(err);
});
});
こんにちはsquez、ご返信ありがとうございます。私はちょっとそれを得ていると思う。 "A.then((B)=> {...})"の入力[B]として使われているものは、[A]であるアクションの前に見ているものからちょうど取り戻されます。 [A] = [B] –