What is the difference between mongoose.Schema()
and new mongoose.Schema()
?
I used both the standards, and I think both do the same job. Does it affect in any way?
Looking at the docs , it should always be called with the new
keyword, since Schema
is a constructor.
Looking at the source code , it'll return a newly allocated object if you try to use it without the new
keyword.
Both will work, but I would only use the first since it's the correct way. Following standard conventions will make your code easier to read; not only for others, but for you as well when you go back to it in 6 months.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.