上一页 1 ··· 112 113 114 115 116 117 118 119 120 ··· 494 下一页
摘要: Source: https://javascriptpatterns.vercel.app/patterns/design-patterns/prototype-pattern If you use factory pattern to create object: const createDog 阅读全文
posted @ 2022-08-26 18:09 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要: In JavaScript, the factory pattern isn't much more than a function that returns an object without using the new keyword. ES6 arrow functions allow us 阅读全文
posted @ 2022-08-26 17:44 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要: Source: https://javascriptpatterns.vercel.app/patterns/design-patterns/singleton-pattern With the Singleton Pattern, we restrict the instantiation of 阅读全文
posted @ 2022-08-26 15:44 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要: Module pattern provide a way to have both public and private pieces with the export keyword. This protects values from leaking into the global scope o 阅读全文
posted @ 2022-08-26 15:18 Zhentiw 阅读(40) 评论(0) 推荐(0)
摘要: import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there’s no remnant of it at ru 阅读全文
posted @ 2022-08-24 14:44 Zhentiw 阅读(102) 评论(0) 推荐(0)
摘要: function isError(err: any): err is Error { return err instanceof Error; } try { somethingRisky() } catch(err: unknown) { if (isError(err)) { console.l 阅读全文
posted @ 2022-08-24 14:23 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要: In some ways // @ts-expect-error can act as a suppression comment, similar to // @ts-ignore. The difference is that // @ts-ignore will do nothing if t 阅读全文
posted @ 2022-08-24 01:46 Zhentiw 阅读(554) 评论(0) 推荐(0)
摘要: CrudController: 查看代码 export const getOne = model => async (req, res) => { try { const doc = model .findOne({ createdBy: req.user._id, _id: req.params. 阅读全文
posted @ 2022-08-23 19:25 Zhentiw 阅读(33) 评论(0) 推荐(0)
摘要: Each model controller: import { crudControllers } from '../../utils/crud' import { Item } from './item.model' export default crudControllers(Item) You 阅读全文
posted @ 2022-08-23 19:23 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要: Model: import mongoose from 'mongoose' const itemSchema = new mongoose.Schema( { name: { type: String, required: true, trim: true, maxlength: 50 }, st 阅读全文
posted @ 2022-08-23 19:20 Zhentiw 阅读(20) 评论(0) 推荐(0)
上一页 1 ··· 112 113 114 115 116 117 118 119 120 ··· 494 下一页