I know about call and apply in javascript and are able to apply them to simple functions, but I get completely confused when it comes to applying them to a chained method call as the one shown below:
db.collection("posts").find({}, {limit:10, sort:[['views', -1]]}).toArray(function(err, posts) {
console.log(posts)
});
Is it possible to pass the arguments from an array, something like [{}, {limit:10, sort:[['views', -1]]} ] into the above method using call or apply ?
I would like to use this to easily access & modify the arguments by keeping them in an external array.
Thank you
I don’t think there’s any way to keep the chaining. You’ll need to store the intermediate result.