2019-10-10 Daily Report

概览

如何肯到清秋日,已带斜阳又带蝉。

时间:Thursday, October 10, 2019 09:30 AM

作者:Syncher Pylon


  • 处理邮件
  • 更新 Todo List
  • 学习算法
  • 学习英语

今日笔记

Promise 知识补充

使用 Promise 读取 hello.txt 文件,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const fs = require("fs");
const samplePromise = new Promise((resolve, reject) => {
console.log(1);
fs.readFile("./hello.txt", { encoding: "utf8" }, function(err, contents) {
console.log(2);
// 读取失败
if (err) {
reject(err);
return;
}
// 读取成功
resolve(contents);
});
});

创建 Promise 时需要传递一个含有两个有名参数的执行函数,我们称之为 excutor,一般而言 excutor 中的有名参数统一命名为 resolvereject。使用最原始的回调函数方式在 excutor 中处理异步逻辑(通常而言,这里的异步逻辑是指调用 JavaScript 执行环境提供的异步API,包括 setTimeout, setInterval, XMLHttpRequst 对象,以及 Node 环境下的很多系统调用),以异步处理结果作为实际参数调用 reject 或者 resolve

至此,我们可以抽象 Promise 如下定义:

1
2
3
4
var Promise = function(excutor) {
// We need to define reject and resolve before call the excutor
excutor(reject, resolve);
}

文件读取成功和失败时,分别执行 resolvereject,这说明 excutor 所需的两个参数都必须是函数类型。因此在 Promise 中执行 excutor 之前需要定义两个函数类型的参数 rejectresolve,如下:

1
2
3
4
5
var Promise = function(excutor) {
function resolve(value) {}
function reject(reason) {}
excutor(reject, resolve);
}

Promise 的使用

1
2
3
4
5
6
7
console.log(3);
samplePromise
.then((data) => {
console.log(data);
}).catch((err) => {
console.log(err);
});
1
2
3
4
5
6
7
8
9
// Define
Promise.catch = function(reject) {
return Promise.then(null, reject)
}

// Invoke
Promise.catch((err) => {
console.log(err.message);
});

Git 使用笔记

  • delete local branch

    1
    2
    $ git branch -d <branch-name> # -d is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch
    $ git branch -D <branch-name> # -D is an alias for --delete --force, which deletes the branch irrespective of its merged status
  • delete remote branch

    1
    $ git push -d <remote-name> <branch-name>

算法学习笔记

重新审视 Binary search

英语学习笔记

Grammer

Prepositions At, on and in (place)

We use at:

  • to refer to a position or location which we see as a point

    e.g. I was sitting at my desk.

    It means I was sitting in the front of desk rather than sitting on the top of desk.

  • to talk about locations at companies, workplaces when we see them as a place of activity

    I am working at SAP

  • to refer to activities which involve agroup of people

    at the party, at the cinema, at the theatre

  • with school/college/university

    at school

  • to refer to an address

    I lived at number 1 Road.

  • to refer to most shops:

    Look what I bought at the butcher’s today.

We use on:

  • to refer to a position on any surface.

    I know I left my wallet on the desk.

  • to talk about a floor in a buiding

    I live on the 17th floor.

  • to describe a positon along a road or river or by the sea or by a lake

    Beijing is on the east of my home.

  • to talk about being physically on public transport

    I was on the train when she phoned.

    but to talk about ways of travelling, we use by: I went to Shanhai by train.

We use in:

  • to talk about locations within a larger area.

    I know my book is somewhere in this room. Can anyone see it?

  • to talk about workspaces when we see them as a physical location

    Elan Wang worked in the shared-office last month.

    but we use on when we talk about a actual location, e.g. I’ve always wanted to work on a farm.

  • with class

    I wasn’t learning grammer in my english class, so I need to self-study again now.

价值参考: https://dictionary.cambridge.org/grammar/british-grammar/prepositions-and-particles

Vocabulary

  • irrespective: 不考虑的,不顾的

    not taking into account; regardless of.

  • respective: 各自的

    belonging or relating separately to each of two or more people or things.

本文标题:2019-10-10 Daily Report

文章作者:Syncher

发布时间:2019年10月10日 - 09:10

最后更新:2019年11月11日 - 23:11

原始链接:https://0x400.com/2019-10-10-diary-2019-10-10.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。