第113期 — 2021-06-27

在浏览器中阅读

周e信

扫描二维码关注微信公众号

Javascript

Nodeca

optional chaining的用法🔗
//调用方法
object?.deepProp?.function?.(args)
//数组
object?.deepProp?.deepArray?.[5]
//表达式 知道就行,不要这样用!
object?.deepProp?.[console.log("runs if deepProp defined")]

Swizec Teller

Colin Eberhardt

Resemble

3 个有用的 TypeScript 模式🔗

映射类型

type Names = "Bob" | "Bill" | "Ben";
type JobTitles = "Welder" | "Carpenter" | "Plumber";

const JobAssignments: { [Key in Names]?: JobTitles } = {
  Bob: "Welder",
  Bill: "Carpenter",
  Ben: "Plumber"
};

函数重载定义

function inputDoubler(input: string): string;
function inputDoubler(input: number): number;

function inputDoubler(input: string | number) {
  if (typeof input === "string"){
    return `${input}${input}`;
  } else {
    return input * 2;
  }
};

inputDoubler(5) + inputDoubler(10);

is

function isPizza (food: Pizza | Burrito): food is Pizza {
  return food.ingredients.topping !== undefined;
};

function printIngredients (food: Pizza | Burrito) {
  if (isPizza(food)) {
    console.log(food.ingredients.topping);
  } else {
    console.log(food.ingredients.filling);
  };
};

CASEY FALKOWSKI

Hemanth.HM

数据库

故事 - 曾经误删生产库且没有正式备份🔗

算是运气好,有个离职的员工离职前偷偷备份了数据库并邮寄给他们恢复--这怎么算?

Francis Stokes

其他

Jay Peters and Jon Porter

Jacob Kaplan-Moss

每个程序员都应该了解的关于 SSD 的知识🔗
  • SSD 通常被称为磁盘,但这是一种误导,因为它们将数据存储在半导体而不是机械磁盘上​​。
  • 磁盘和 SSD 之间的另一个重要区别是磁盘只有一个磁头,并且仅在顺序访问时性能良好。相比之下,SSD 由数十个甚至数百个闪存芯片(“并行单元”)组成,可以同时访问。

Viktor Leis

DAN GOODIN

LAXMAN MUTHIYAH

Mike D. Sykes, II

LANDrop

Travis Breaux

扫描二维码关注微信公众号
本期阅读量