weekly 201-03-28

12次阅读

共计 960 个字符,预计需要花费 3 分钟才能阅读完成。

学东西要知其然并且知其所以然 另外,实践出来的感悟和别人分享的感悟是不一样的

[] 垂直居中布局
[x] 浏览器缓存
[] tcp 连接
[] 状态码 301 302 307
[x] bind 方法实现
[x] new 关键字实现
[] 最长公共子序列
[] react 中 pureComponent hooks
[x] 箭头函数
[] window.onload() && $(document).ready()

浏览器缓存有一个注意点
Etag 优先级比 LastModified 高, lastmodified 最后修改时间只能精确到秒,如果 1s 内多次修改,捕捉不到
另外,有些资源内容没有变,但 lastmodified 变了,etag 可以防止不使用缓存
bind 方法简单实现
Function.prototype.bind = function() {
var self = this;
var o = Array.prototype.shift.call(arguments);
var arg1 = Array.prototype.slice.call(arguments);
return function (…args) {
return self.apply(o, arg1.concat([…args]));
}
}
箭头函数的一些特点总结
let play = () => { consoel.log(this) }
1. 箭头函数没有原型,所以箭头函数没有 this
play.prototype == undefined
2. 箭头函数的 this 指向定义时候所在外层 this 指向, 跟使用位置没有关系
this === window
3. 箭头函数 this 指向 window 时,没有 arguments
let bar = () => { console.log(arguments) }// 报错
箭头函数的 this 指向普通函数时,它的 arguments 可继承
function bar() {
let foo = () => {
console.log(arguments)
}
foo() // 可以打印
}

var name = ‘b’;
var o = {
name: ‘a’,
key : () => {
console.log(this.name) // b
}
}

var o2 = {
name: ‘a’,
key : function() { console.log(this.name)} // a
}

4. 箭头函数不能使用 new 关键字 因为没有 constructor

正文完
 0