这个是我以前看前端跳槽面试必备技巧这个系列视频整理的一个笔记,其中还有一些内容没有细化,会持续更新细化内容。比较短的就会直接写在下面,长一点的就单独写篇文章。css
说实话,这个大佬真的讲的挺好的,尤为是对原型和继承那一块讲的通俗易懂。有些店以前看视频的时候看不懂或者没有在乎,其实仍是有蛮多点可挖的,我也还会针对一些没太吃透的点重点再写文章记录。html
例子:假设高度已知,请写出三栏布局,其中左右栏宽度都是300px,中间自适应前端
html * { margin: 0; padding: 0; } .layout .item { height: 100px; } .layout { margin-bottom: 30px; }
<!-- 浮动布局 --> <section class="layout float"> <style> .layout.float .left { float: left; width: 300px; background-color: #555; margin-right: 10px; } .layout.float .center { background-color: #777; } .layout.float .right { float: right; width: 300px; background-color: #999; } </style> <article class="left_center_right"> <div class="item left"></div> <div class="item right"></div> <div class="item center"> <h2>浮动布局</h2> <p>这是浮动布局的内容</p> </div> </article> </section>
<!-- 绝对布局 --> <section class="layout absolute"> <style> .layout.absolute .left_center_right .item { position: absolute; } .layout.absolute .left { left: 0; width: 300px; background-color: #555; } .layout.absolute .center { left: 300px; right: 300px; background-color: #777; padding-left: 10px; } .layout.absolute .right { right: 0; width: 300px; background-color: #999; } </style> <article class="left_center_right"> <div class="item left"></div> <div class="item center"> <h2>绝对布局</h2> <p>这是绝对定位布局的内容</p> <p>这是绝对定位布局的内容</p> <p>这是绝对定位布局的内容</p> </div> <div class="item right"></div> </article> </section>
<!-- flexbox 布局 --> <section class="layout flexbox"> <style> .layout.flexbox { margin-top: 160px; } .layout.flexbox .left_center_right { display: flex; display: -webkit-flex; } .layout.flexbox .left { width: 300px; background-color: #555; } .layout.flexbox .center {; background-color: #777; flex: 1; padding-left: 10px; } .layout.flexbox .right { width: 300px; background-color: #999; } </style> <article class="left_center_right"> <div class="item left"></div> <div class="item center"> <h2>flex布局</h2> <p>这是flex布局的内容</p> <p>这是flex布局的内容</p> <p>这是flex布局的内容</p> </div> <div class="item right"></div> </article> </section>
<!-- table 布局 --> <section class="layout table"> <style> .layout.table .left_center_right { width: 100%; height: 100px; display: table; } .layout.table .left_center_right .item { display: table-cell; } .layout.table .left { width: 300px; background-color: #555; } .layout.table .center {; background-color: #777; padding-left: 10px; } .layout.table .right { width: 300px; background-color: #999; } </style> <article class="left_center_right"> <div class="item left"></div> <div class="item center"> <h2>table布局</h2> <p>这是table布局的内容</p> <p>这是table布局的内容</p> <p>这是table布局的内容</p> </div> <div class="item right"></div> </article> </section>
grid-template-rows: 设置列的高度webpack
<!-- 网格 布局 --> <section class="layout grid"> <style> .layout.grid .left_center_right { width: 100%; height: 100px; display: grid; grid-template-columns: 300px auto 300px; grid-template-rows: 100px; } .layout.grid .left { width: 300px; background-color: #555; } .layout.grid .center {; background-color: #777; padding-left: 10px; } .layout.grid .right { width: 300px; background-color: #999; } </style> <article class="left_center_right"> <div class="item left"></div> <div class="item center"> <h2>网格布局</h2> <p>这是grid布局的内容</p> <p>这是grid布局的内容</p> <p>这是grid布局的内容</p> </div> <div class="item right"></div> </article> </section>
- DOM0: element.onclick=function(){} - DOM1: element.addEventListener('click',function(){},false) - DOM3: element.addEventListener('keyup',function(){},false) (增长了不少事件)
window: window.addEventListener('click', function(){ console.log('window'); }, true) document: document.addEventListener('click', function(){ console.log('document'); }, true) html: document.documentElement.addEventListener('click', function(){ console.log('html'); }, true) body: document.body.addEventListener('click', function(){ console.log('body'); }, true)
- event.preventDefault() 阻止默认事件 - event.stopProgation() 阻止冒泡 - event.stopImmediateProgation() 设定事件响应优先级 - event.currentTarget 当前所绑定的事件 - event.targe 当前被点击的元素
例如:自定义一个自定义事件'custome' var eve=new Event('custome'); ev.addEventListener('custom',function(){ console.log('custome'); }) ev.dispatchEvent(eve);
管线化不会影响响应到来的顺序css3
建立对象有几种方法nginx
// 第一种很方式:字面量 var o1 = {name: 'o1'}; var o11 = new Object({name: 'o11'}); // 第二种方式:经过构造函数 var M = function(){ this.name = 'o2'; } var o2 = new M(); // 第三种方式:Object,create var P = {name: 'o3'}; var o3 = Object.create(P);
M的原型对象:M.prototype
M.prototype.constructor === M 任意一个实例对象o2 o2.__proto__.constructor === M 这个能够用来判断实例对象的构造函数
o2.__proto__ === M.prototype
原型链的顶端是Object.prototype这个原型对象的原型Object.prototype.__proto__为空
var new2 = function(func){ var o = Object.create(func.prototype); var k = func.call(o); if (typeof k === 'object') { return k }else{ return o } } o6 = new2(M); 这个就等价于对构造函数M实例化了一个实例对象
/*类的声明*/ function Animal () { this.name = 'name'; } /*ES6中的类的声明*/ class Animal2 { constructor (name) { this.name = name; } }
/*实例化类的对象*/ console.log(new Animal(), new Animal2())
/*借助构造函数实现继承*/ function Parent1 () { this.name = 'parent1'; } function Child1 () { Parent1.call(this); //就是将Child1运行在Parent1的上下文环境里 // Parent1.apply(this, []); //另外一中写法 this.type = 'child1'; } console.log(new Child1)
/*利用原型链实现继承*/ function Parent2 () { this.name = 'parent2'; this.play = [1,2,3]; } function Child2 () { this.type = 'child2'; } Parent2.prototype.say = function () {console.log('hello')}; Child2.prototype = new Parent2(); //实际上这个方法就是至关于把Parent2的原型链嫁接到了Child2上,因此子级能经过原型链访问到父级的方法了 console.log(new Child2()); // (new Child2()).__proto__ === Child2.prototype = new Parent2(),因此子集实例的原型链指向的是父级的一个实例 var s1 = new Child2(); var s2 = new Child2(); s1.play.push(7); console.log(s1.play, s2.play); //他们永远会是相等的,由于他们指向的地址是同样的,他们的原型对象是同样的,s1.__proto__===s2.__proto__
/*组合方式*/ function Parent3 () { this.name = 'parent3'; this.play = [1,2,3]; } function Child3 () { Parent3.call(this); this.type = 'child3'; } Child3.prototype = new Parent3(); //构造函数Parent3执行了两次,有一次是多余的 var s3 = new Child3(); var s4 = new Child3(); s3.play.push(6); console.log(s3, s4)
/*组合方式优化1*/ function Parent4 () { this.name = 'parent4'; this.play = [1,2,3]; } function Child4 () { Parent4.call(this); this.type = 'child4'; } Child4.prototype = Parent4.prototype; //这样构造函数Parent4就只执行了一次 console.log(Parent4.prototype) var s5 = new Child4(); var s6 = new Child4(); var s6_ = new Parent4(); console.log(s5 instanceof Child4, s5 instanceof Parent4); console.log(s5.constructor); console.log(s6_.constructor); //都指向了构造函数Parent4
/*组合方式优化2*/ // 这种优化方式是为了解决没法分辨父级和子级的实例对象的问题,也就是说父级和子级的实例对象都指向了同一个原型对象 function Parent5 () { this.name = 'parent5'; this.play = [1,2,3]; } function Child5 () { Parent5.call(this); this.type = 'child5'; } Child5.prototype = Object.create(Parent5.prototype); //至关于建立了一个空的中间对象,这样的话子级构造函数的原型对象不是简单地与父级构造函数的原型函数相等了,而是先等于一个空的中间对象,再对这个中间的对象进行赋值 Child5.prototype.constructor = Child5; //这一步实际上就是作的赋值,固然没有上面那步让子级的构造函数的原型对象先等于一个空对象的话仍是没法将他们分开的 var s7 = new Child5(); var s8 = new Child5(); var s9 = new Parent5(); console.log(s7 instanceof Child5, s8 instanceof Parent5) console.log(s7.constructor) console.log(s9.constructor)
console.log(1); setTimeout(function(){ console.log(2) }, 0) console.log(3); 打印顺序是:1,3,2,由于setTimeout是异步任务
console.log('A'); setTimeout(function(){ console.log('C'); },0) while(1){ console.log(5) } console.log('B'); 会输出:A; 由于while是一个同步任务,会优先执行这个任务,可是这个while循环是一个死循环,会一直陷在循环中,那后面的打印和定时器的异步任务都不会执行了
for (var i = 0; i < 4; i++) { setTimeout(function(){ console.log(i); },1000) } 输出结果: 4个4
<meta http-equiv="x-dns-prefetch-control" content="on"> 这句话是说在https协议下默认强制让页面上全部的a标签也能够DNS预解析 <link rel="dns-prefetch" href=".."> 针对某一个域名DNS预解析