這個是我以前看前端跳槽面試必備技巧這個系列視頻整理的一個筆記,其中還有一些內容沒有細化,會持續更新細化內容。比較短的就會直接寫在下面,長一點的就單獨寫篇文章。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預解析