是否可以创建匿名异步功能?
当然,命名函数有效:
const test = async() => {
await ... //fetch some data
}
但是未命名的异步函数的有效语法是什么?我们应该在这里使用IIFE吗?
答案 0 :(得分:1)
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var countrySchema = new Schema({
country_id:String,
country_name:String
});
var countryArray = mongoose.model('countryArray',countrySchema);
var stateSchema = new Schema({
state_id:String,
state_name:String,
country: { type: Schema.Types.ObjectId, ref: 'countryArray' },
});
var states = mongoose.model('states',stateSchema);
答案 1 :(得分:0)
async function() => {
await ...
}
答案 2 :(得分:0)
双向,
!async function () {
console.log("e",'yibu');
}();
或
(async () => {
console.log("e",'yibu');
})();
//maybe this is better then above
;(async function () {
console.log("e",'yibu');
}());
//this is allmost same
;[ async function () {
console.log("e",'yibu');
}()];
var x=async () => 100;
x().then(
e=>console.log({e})
);