在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
This lesson introduces the
Chaining Operator for Function: type SerializationOptions = { formatting?: { getIndent?: () => number; }; }; function serializeJSON(value: any, options?: SerializationOptions) { const indent = options?.formatting?.getIndent?.(); return JSON.stringify(value, null, indent); } const user = { name: "Marius Schulz", twitter: "mariusschulz", }; const json = serializeJSON(user, { formatting: { getIndent: () => 2, }, }); console.log(json);
For Array Syntax: type SerializationOptions = { formatting?: { "indent-level"?: number; }; }; function serializeJSON(value: any, options?: SerializationOptions) { const indent = options?.formatting?.["indent-level"]; return JSON.stringify(value, null, indent); } const user = { name: "Marius Schulz", twitter: "mariusschulz", }; const json = serializeJSON(user, { formatting: { "indent-level": 2, }, }); console.log(json);
|
请发表评论