前言

忽略我这个中文式英语的标题。

身为一个记性不咋地的前端渣渣,觉得平时看的一些文章太散了,特开此文作为一种记录,可谓好记性不如烂笔头,也算是逼自己要经常学习。文章的日期为最后更新时间,题目顺序不分先后,希望能经常保持置顶状态,目录到达一定长度时会重开一篇。

工具

hexo迁移

因为我的笔记本电脑最近瓦特了,所以不得不把博客迁出来,在这里做个记录,方便下次查找。

  • 将原来的电脑上原有的hexo目录拷贝到新电脑,只需拷贝以下目录:

    • _config.yml
    • package.json
    • scaffolds/
    • source/
    • themes/
  • 在新电脑安装hexo

    npm install -g hexo

  • 安装后进入hexo/目录

  • 安装模块

    1
    2
    3
    4
    npm install
    npm install hexo-deployer-git --save
    npm install hexo-generator-feed --save
    npm install hexo-generator-sitemap --save
  • 然后重新配置github

    1
    2
    git config --global user.name "YOUR NAME"
    git config --global user.email "YOUR EMAIL ADDRESS"

    Authenticating with GitHub from Git

    • 在 Git Bash 下执行如下命令,生成 SSH key

      ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

      email为自己的github账号,剩下的一路回车即可。

    • 将 SSH key 添加到 ssh-agent

      • 在 Git Bash 下执行如下命令,开启 ssh-agent

      eval "$(ssh-agent -s)"

      • 将这个 SSH key 添加到 ssh-agent 里去

      ssh-add ~/.ssh/id_rsa

    • 将 SSH key 添加到 Github 账户

      • 在 Git Bash 中将 SSH Key 拷贝出来:

      clip < ~/.ssh/id_rsa.pub

      此时,SSH Key 已经在我们的剪切板里了。然后登录 Github 帐号,依次点击自己的头像,SettingsSSH and GPG keysAdd SSH key, 在 Title 这里输入 Key 的label,比如 your_name - PC,然后在 Key 里面把 SSH Key 粘贴进去,点击 Add SSH key 大功告成。

    • 测试 SSH 连接,在 Git Bash 中敲入

    ssh -T git@github.com

  • 做完上面这些后 执行hexo deploy 大功告成

  • 但是我还是报错,hexo error fatal httprequestexception encountered….

    后来在https://github.com/hexojs/hexo/issues/3043 这里找到解决方法

    把repo的配置方式改一下,任何就可以了。

    1
    2
    3
    4
    deploy:
    type: git
    repo: git@github.com:anchen1204/anchen1204.github.io.git
    branch: master

    以上方法结合了这两篇文章:

    hexo:更换电脑,如何继续写博客

    多机更新 Hexo 博客

JavaScript

Object.assign()

语法:Object.assign(target, ...sources );

参数:

target:必需。可枚举属性复制到的对象。

…sources:必需。从其中复制可枚举属性的对象。

实例:

1
2
3
4
5
var first = { name: "Bob" };
var last = { lastName: "Smith" }; var person = Object.assign(first, last);
console.log(person);

看阮一峰大神的ES6-编程风格 :

对象尽量静态化,一旦定义,就不得随意添加新的属性。如果添加属性不可避免,要使用Object.assign方法。

1
2
3
4
5
6
7
8
9
10
11
// bad
const a = {};
a.x = 3; // if reshape unavoidable
const a = {};
Object.assign(a, { x: 3 }); // good
const a = { x: null };
a.x = 3;

Promise

阅读(按左到右顺序): 大专栏  Day learn,day up/zh-CN/docs/Web/JavaScript/Guide/Using_promises" target="_blank" rel="noopener noreferrer">使用 Promises Promise

这两天又看了一遍Promise的内容,觉得这个对象真的非常好用。

做个总结呗,其实在项目中已经快乐地用起来了,很方便。

它存在的意义?还不是因为javaScript是世界上最好的…不对,说错台词了,应该是javaScript是单线程语言。

我们经常为了解决这个问题,使用的是回调函数,俗称callback,为了达到异步执行。比如setTimeout ,比如AJAX异步操作。

具体介绍不表,可以看文档。直接说使用吧。

1
new Promise( function(resolve, reject) {...} /* executor */  );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
new Promise((resolve, reject) => {
console.log('Initial'); resolve();
})
.then(() => {
throw new Error('Something failed'); console.log('Do this');
})
.catch(() => {
console.log('Do that');
})
.then(() => {
console.log('Do this whatever happened before');
});

.then()是链式调用,获取上一个Promise resolve返回的对象进行操作;

.catch() 原理同then,但是是针对Promise 的reject返回的对象进行操作;

注意:在一个失败操作(即一个 catch)之后可以继续使用链式操作,即使链式中的一个动作失败之后还能有助于新的动作继续完成。

即链式调用不会因为其中一个环节失败(reject)而中断。

好用组合:

Promise.resolve() &Promise.reject()

这两个是手动创建一个已经resolve或者reject的promise快捷方法。

Promise.race()Promise.all()

这两个用法一样,其实括号内都是多个Promise对象

但是不同的地方在于:

Promise.all(iterable) 方法返回一个 Promise 实例,此实例在 iterable参数内所有的 promise 都完成(resolved),或参数中不包含 promise 时回调完成(resolve);如果参数中 promise 有一个失败(rejected),此实例回调失败(reject),失败原因的是第一个失败 promise 的结果。

Promise.race(iterable)方法返回一个 promise,一旦迭代器中的某个promise解决或拒绝,返回的 promise就会解决或拒绝。

一句话,前者如果有一个失败,则之间返回第一个失败(catch里);后者只会返回第一个处理的失败或者成功。

举个实际可能会使用的例子:

Promise.all是很适合来解决多个Promise是用于获取请求基本信息,比如app里的登陆信息,ticket,版本号,它们都获取成功后可以接着执行可能下一步的请求。。。

Promise.race很适合容错现象,比如接口超时:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//网络超时写法:Promise.race()
let promise1 = new Promise(resolve=>{
setTimeout(()=>{
return '数据已返回';
},5000)
})
let promise2= new Promise(reject=>{
setTimeout(()=>{
reject('网络超时')
},4000)
})
Promise.race([promise1,promise2]).then(res=>{
console.log(res)
}).catch(res=>{
console.log(res)
})

Day learn,day up的更多相关文章

  1. Atitit learn by need 需要的时候学与预先学习知识图谱路线图

    Atitit learn by need 需要的时候学与预先学习知识图谱路线图 1. 体系化是什么 架构 知识图谱路线图思维导图的重要性11.1. 体系就是架构21.2. 只见树木不见森林21.3. ...

  2. Python 爬取所有51VOA网站的Learn a words文本及mp3音频

    Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...

  3. [转载]VIM 教程:Learn Vim Progressively

    文章来源:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/   Learn Vim Progressively   TL ...

  4. some tips learn from work experience

    1.you can't avoid office politics 2.you'll never have a job which you "can't quit" - if yo ...

  5. Java-集合(没做出来)第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseL

    没做出来 第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列. 例如: List list = new ArrayList(); list.a ...

  6. Learn RxJava

    Learn RxJava http://reactivex.io/documentation/operators.html https://github.com/ReactiveX/RxJava/wi ...

  7. ANSI Common Lisp Learn

    It has been a long time that I haven't dealt with my blog. On one hand I was preparing the exams.On ...

  8. [Notes] Learn Python2.7 From Python Tutorial

    I have planed to learn Python for many times. I have started to learn Python for many times . Howeve ...

  9. 十分钟入门less(翻译自:Learn lESS in 10 Minutes(or less))

    十分钟入门less(翻译自:Learn lESS in 10 Minutes(or less)) 注:本文为翻译文章,因翻译水平有限,难免有缺漏不足之处,可查看原文. 我们知道写css代码是非常枯燥的 ...

  10. Learning How To Learn

    1.Practice 2.memory every week for from working memory to long tern memory 3.sleep 4.running promote ...

随机推荐

  1. 一、早期(Early Stage)

    一.早期(Early Stage) 如果单纯从零基础开始,早期(Early Stage)应该是一到两个月(由于英语与中文差异比与其他语言大,中国同学至少两个月,但也不应过长.我们的经验是一般中国同学会 ...

  2. 如何正确理解SQL关联子查询

    一.基本逻辑 对于外部查询返回的每一行数据,内部查询都要执行一次.在关联子查询中是信息流是双向的.外部查询的每行数据传递一个值给子查询,然后子查询为每一行数据执行一次并返回它的记录.然后,外部查询根据 ...

  3. tensorflow实现卷积层的几种方式

    #coding:utf-8 #第一种实现 tf.nn import tensorflow as tf import tensorflow.contrib.slim as slim tf.reset_d ...

  4. ruoyi IpUtils

    package com.ruoyi.common.utils; import java.net.InetAddress; import java.net.UnknownHostException; i ...

  5. 关于前端Dom的总结

    简介 DOM (Document Object Model) 文档对象模型 DOM思想使用节点树(node tree)的概念来描述一个HTML页面,页面中的每一个元素.属性.文本都被认为是节点.此外, ...

  6. 5G时代将至,哪些改变会随之而来?

    近年来,运营商不断被唱衰.关键原因就在于运营商的各项业务,在互联网的冲击下已经愈发"萎缩".尤其是短信和语音通话,它们的价值在不断被降低.简而言之,运营商似乎成为了纯粹的" ...

  7. js中使用EL表达式总结

    1.js中使用el表达式要加双引号或单引号:'${list}' 2.js变量获取el表达式中的对象:不能直接获取,直接获取得到的是该对象的toString值. 有两种方法:一:el中直接写对象的属性v ...

  8. 为什么wget只下载某些网站的index.html? wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com wget 下载整个网站,或者特定目录

    wget -c -r -np -k -L -p http://blog.hesheyou.me -c, –continue 接着下载没下载完的文件 -r, –recursive 递归下载 -np, – ...

  9. 26)PHP,数据库表格中项的数据类型

    类型展示: tinyint-----1个字节 smallint----2个字节 mediumint--3个字节 int------4个字节 bigint---8个字节 字符串类型 最基本最重要的2个: ...

  10. 39)PHP,选取数据库中的两列

    首先是我的文件关系: 我的b.php是主php文件,BBB.php是配置文件,login.html是显示文件, b.php文件代码: <?php /** * Created by PhpStor ...