var createManyPeople = function(arrayOfPeople, done) {
Person.create(arrayOfPeople, function(err, data){
if(err){
done(err);
} else {
done(null, data);
}
});
};
what is the “done” function here?
var createManyPeople = function(arrayOfPeople, done) {
Person.create(arrayOfPeople, function(err, data){
if(err){
done(err);
} else {
done(null, data);
}
});
};
what is the “done” function here?
Done looks like a callback function for when the Person.create function is done with errors or without errors
Sure, so take a look in the very first line:
var createManyPeople = function(arrayOfPeople, done) {
In that line, we have two parameters that are going into the function: an array of people, and a callback function to run at completion. done
is a function we can pass in (remember, in javascript, functions are treated like data, just as strings or numbers or arrays, so we can chuck 'em around anytime!).
This is a pretty common trick, to allow a function to be passed in and then to call that function when a given condition has been met.