面試技巧 頁面佈局類 CSS盒子模型類 DOM事件 HTTP協議類 面向對象類 原型鏈類 通訊類 安全類 算法類css
面試技巧
1)準備要充分,基礎知識要紮實
2)知識要系統,前端知識點太碎,要有總體的把握
3)溝通要簡介,一面考基礎,不要拖泥帶水,一語中的
4)心裏要誠實,會就是會,不會就是不會,不要說什麼,我看過,可是我忘了,這樣子的話很讓面試官反感
5)態度要謙虛,一面是基礎面,不須要太深刻,點到爲止,不要一直和麪試官深刻講,讓他以爲你高傲,目中無人
6)回答要靈活,不要把我說的太死,不要說 「就是這樣子」 這類的話。這個尤爲要注意,有的人是口頭就習慣了這麼說,好比,回答某個問題,多用「能夠是,能夠用」這樣的修辭,不要說 「就是」 這樣子的修飾語html
頁面佈局類
題目1:假設高度已知,寫出三欄佈局,其中左欄,右欄寬度各爲300px,中間寬度自適應,這裏至少要寫出5中佈局方案 前端
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{ margin: 0px; padding: 0px; } .box div{ height: 100px; } .left{ background: red; float: left; width: 200px; } .right{ background: blue; float: right; width: 200px; } .middle{ background: yellow } </style> </head> <body> <div class="box"> <div class="left">1</div> <div class="right">2</div> <div class="middle">3</div> </div> </body> </html>
2)絕對定位面試
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style type="text/css"> *{ padding: 0px; margin:0px; } .box div{ position: absolute; height: 100px; } .left{ left: 0px; width: 300px; background: red; } .middle{ left: 300px; right: 300px; background: yellow } .right{ right: 0px; width: 300px; background: blue } </style> <body> <div class="box"> <div class="left"></div> <div class="middle"></div> <div class="right"></div> </div> </body> </html>
3)flex佈局ajax
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style type="text/css"> *{ padding: 0px; margin:0px; } .box{ height: 100px; display: flex; } .left{ flex:0 0 300px; background: red; } .middle{ background: yellow; flex: 1 1 auto } .right{ flex:0 0 300px; background: blue } </style> <body> <div class="box"> <div class="left"></div> <div class="middle"></div> <div class="right"></div> </div> </body> </html>
4)table-cell佈局算法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style type="text/css"> *{ padding: 0px; margin:0px; } .box{ height: 100px; display: table; width: 100% } .box div{ display: table-cell; } .left{ background: red; width: 300px; } .middle{ background: yellow; } .right{ background: blue; width: 300px; } </style> <body> <div class="box"> <div class="left"></div> <div class="middle"></div> <div class="right"></div> </div> </body> </html>
5)grid佈局後端
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style type="text/css"> *{ padding: 0px; margin:0px; } .box{ display: grid; width: 100%; grid-template-rows:100px; grid-template-columns:300px auto 300px; } .left{ background: red; } .middle{ background: yellow; } .right{ background: blue; } </style> <body> <div class="box"> <div class="left"></div> <div class="middle"></div> <div class="right"></div> </div> </body> </html>
題目2:這5種方法的特色是什麼,各有什麼優勢缺點跨域
1)浮動佈局:缺點是浮動的破壞性和包裹性,會涉及到清除浮動的知識點,優勢是兼容性好
瀏覽器
2)絕對定位:絕對定位的破壞性,脫離文檔流,優勢是方便快捷緩存
3)flex佈局:解決以上兩種佈局的不足,在移動端很流行,可是兼容性出現了問題,不支持ie8
4) table佈局:單元格約束性太強,麻煩,可是能夠解決flex佈局不能兼容ie8的問題
5)grid佈局:寫出來是爲了體現你關注熱點技術,讓面試官看到你的技術追求
題目3:若是高度未知,假如中間的內容不少,撐開了,但願左側和右側的高度也隨之撐開。以上5種佈局,還有哪些能夠實現,哪些已經做廢
浮動佈局,絕對定位,都會出現問題,浮動佈局會出現一個文字環繞效果,絕對定位會撐開中間元素,
flex佈局和表格佈局,還有網格佈局,左右兩邊的寬度會增長,仍是能夠實現
延伸:怎麼樣去除浮動佈局的文字環繞效果,讓內容不影響左右佈局,建立BFC等知識點,點擊這裏
頁面佈局類總結:語義化掌握到位 頁面佈局理解深入 CSS基礎知識紮實 思惟靈活積極向上 代碼書寫規範,這些很重要,現場寫代碼,面試官是很注重代碼的規範的
CSS盒模型類
題目1:談談你對CSS盒子模型的認識
基本概念:標準模型+IE模型
題目2:標準模型和IE模型的區別
這個我在之前的博客總結過的,點擊這裏查看
題目3:CSS是如何設置這兩種模型的
box-sizing:content-box 標準模型
box-sizing:border-box IE模型
題目4:JS如何設置和獲取盒模型對應的寬高
dom.style.width/height 只能取到內聯的樣式
dom.Currentstyle.width/height只有IE支持
window.getComputedStyle(dom).width/height
dom.getBoundingClientRect().width/height
題目5:根據盒模型解釋邊距重疊
題目6:BFC的基本概念,工做原理,如何建立,以及使用場景
題目5,6,設計到了BFC的知識,我在別的博客整理過的,點擊這裏
DOM事件類
題目1:DOM事件的級別
DOM0 elem.onclick=function(){}
DOM2 elem.addEventListener(‘click’,function(){},true)
DOM3 elem.addEventListener(‘keyup’,function(){},true)
題目2:DOM事件模型
捕獲和冒泡
題目3:DOM事件流
捕獲--目標階段--冒泡
題目4:描述DOM事件捕獲的具體流程
捕獲過程 window —document—-html—body—普通元素
題目5:Event事件的常見應用
event.preventDefault() event.stopPropagation() event.stopImmediatePropagation() event.currentTarget event.target
題目6:自定義事件
var eve=new Event(‘custom); ev.addEventListener(‘custom’,function(){ console.log(‘custom’); }) ev.dispatchEvent(eve)
HTTP協議類
題目1:HTTP協議的主要特色
簡單快速:每一個資源的url是固定的,訪問方便
靈活:http協議的的頭部能夠設置數據類型,完成不一樣數據類型的傳輸
無鏈接:鏈接一次就會斷掉
無狀態:客戶端和服務端是兩種身份
題目2:HTTP報文的組成方法
請求報文:請求行,請求頭,空行,請求體
響應報完:狀態行,響應頭,空行,相應體
題目6:什麼事持久鏈接
題目7:什麼是管線化
var obj1={ name:'lili' }
var obj2 = new Object({
name:'lucy'
})
這裏,我把這兩種方法都總結在了一塊兒,由於對象實際上,都是經過Object這個構造函數生成的,上面的方法只是一種簡寫,語法糖而已
第二種function Obj(){ this.name='jack' }
var obj3=new Obj()
這個就是經過構造函數的方式,生成一個對象,也是很簡單的
第三種var obj4={ name:'fack' } var obj5=Object.create(obj4)
console.log(obj5.name) //fack console.log(obj5.hasOwnProperty(name)) //false
這也是建立對象的一種方式,這個Object.create方法,不知道的能夠去這裏看看
就是說,obj5對象的原型,直接指向了obj4,因此obj5擁有name屬性,可是這個是原型鏈上的屬性,不是本身的屬性
題目2:原型,構造函數,實例,原型鏈function M(){ this.age=21 } var obj=new M()
console.log(obj instanceof M) //true console.log(M.prototype instanceof Object) //true console.log(obj instanceof Object) //true
obj的_proto_屬性,和M的prototype屬性,指向同一個地址,因此 obj instanceof M 爲true
M.prototype是一個對象,而找個對象是經過構造函數Object產生的,因此,M.prototype instanceof Object 也是爲 true
再看第三行,你就會發現,只要是沿着這一條原型鏈,都會返回true
function newObj(fn){ var obj=Object.create(fn.prototype) fn.apply(obj) return obj } function M(){ this.age=21 } var obj=newObj(M) console.log(obj)
這個是模擬的構造函數的寫法,從這個代碼能夠看出來new運算符的工做原理
funciton Animal(){ this.name='name' }
也許這個說法不是很嚴謹,在js當中,構造函數充當了類的做用
class Animal2{ constructor(){ this.name=name } }
這是ES6當中的新寫法,你能寫出來,面試官也會喜歡的,體現你的技術追求嘛
var a = new Animal() var b = new Anima2()
生成實例的方法是同樣的,都是構造函數調用,很簡單
function Parent1(){ this.age=21 } function Child1(){ this.name='lili' } Child1.prototype=new Parent1() var chi=new Child1() console.log(chi)
直接看這個截圖,因爲咱們 Child1.prototype=new Parent1(),因此,將chi的原型指向了parent1,是實現了繼承
這個方法存在問題嗎?
function Parent1() { this.frid = [1,2] } function Child1() { this.name = 'lili' } Child1.prototype = new Parent1() var chi = new Child1() var chi2 = new Child1() chi.frid.push(3) console.log(chi2.frid) //[1,2,3]
看到問題了吧,因爲這兩個實例對象的原型是同一個引用,當操做一個的時候,另外一個也是會發生變化的
咱們能夠測試的看看
console.log(chi.__proto__===chi2.__proto__) //true
這兩個對象的原型,是嚴格相等的。
2)構造函數實現繼承
function Parent1(){ this.age=21 } function Child1(){ Parent1.apply(this) this.name='lili' } var chi=new Child1() console.log(chi)
Parent1.apply(this)
這行代碼的做用很大,在Child函數裏面,執行了Parent函數,並且,將這個Parent函數的上下文,綁定到了this,在這裏,這個this表示的是實例對象chi
爲何不這麼寫?
Parent1.apply(Child1)
function Parent1(){ this.age=21 } function Child1(){ Parent1.apply(Child1) this.name='lili' } var chi=new Child1() console.log(chi.age) //undefined
這至關於,把age這個屬性,添加到了Child1上面,可是並不會被Child1的實例對象所擁有
仍是回到最開始的正確狀態的構造函數實現繼承,這種方法的問題是什麼?
function Parent1(){ this.age=21 } function Child1(){ Parent1.apply(this) this.name='lili' } Parent1.prototype.sex = function() {} var chi=new Child1() console.log(chi.sex) //undefined
能夠看到,這個chi實例對象,只能繼承 Parent對象的屬性,不能繼承這個對象原型鏈上的屬性,只能實現部分的繼承
function Parent1() { this.frid = [1,2] } function Child1() { Parent1.apply(this) this.name = 'lili' } Child1.prototype = new Parent1() var chi = new Child1() var chi2 = new Child1() chi.frid.push(3) console.log(chi.frid) //[1,2,3] console.log(chi2.frid) //[1,2] console.log(chi.__proto__===chi2.__proto__) //true
這個寫法非常神奇啊,兩個的原型指向的是同一個對象
這個Parent函數但是執行了兩次的啊,發現沒有
4)組合繼承的優化方式
function Parent1() { this.frid = [1,2] } function Child1() { Parent1.apply(this) this.name = 'lili' } Child1.prototype = Parent1.prototype var chi = new Child1() var chi2 = new Child1() chi.frid.push(3) console.log(chi) console.log(chi2) console.log(chi.__proto__===chi2.__proto__)
這個和構造函數相比,僅僅是多了一行,構造函數繼承的方式當中,沒辦法繼承Parent的原型屬性,因此咱們手動添加
Child1.prototype = Parent1.prototype 這一行代表,Parent的原型添加到了Child的原型上面,因此,能夠繼承Parent的原型了
可是這個方法仍是會出現問題的,請看
function Parent1() { this.frid = [1, 2] } function Child1() { Parent1.apply(this) this.name = 'lili' } Child1.prototype = Parent1.prototype var chi = new Child1() console.log(chi instanceof Child1) //true console.log(chi instanceof Parent1) //true console.log(chi.constructor == Child1) //false console.log(chi.constructor == Parent1) //true
chi竟然不是Child的直接實例,竟然變成了Parent的實例
咱們知道,這個函數的prorotype指向的是一個對象,這個對象有一個constructor屬性,這個屬性又指向了這個函數對象
chi沒有本身的constructor屬性,因此沿着原型鏈查找,他的原型對象,也就是 Child1.prototype,可是,找個對象被從新賦值爲了 Parent1.prototype,那麼Parent1.prototyped的constructor指向什麼?
固然是他本身啊—-Parent1
再回頭去看看之前的寫法,只要的原型鏈的方式繼承,都會改變原來的 constructor 的指向
5)組合繼承的優化方式 2
function Parent1() { this.frid = [1,2] } function Child1() { Parent1.apply(this) this.name = 'lili' } Child1.prototype =Object.create(Parent1.prototype)
Child1.prototype.constructor=Child1 var chi = new Child1() console.log(chi.constructor)
這兩行代碼,一個都不能少,也許有人好奇了?爲何前面的代碼,不直接加一句 Child1.prototype.constructor=Child1呢?
function Parent1() { this.frid = [1,2] } function Child1() { Parent1.apply(this) this.name = 'lili' } Child1.prototype = Parent1.prototype Child1.prototype.constructor=Child1 var chi = new Child1() var pat=new Parent1() console.log(chi.constructor) console.log(pat.constructor)
這個會致使,pat.constructor也變成了 Child 構造函數,顯然,是存在問題的
function Parent1() { this.frid = [1,2] } function Child1() { Parent1.apply(this) this.name = 'lili' } Child1.prototype =Object.create(Parent1.prototype) Child1.prototype.constructor=Child1 var chi = new Child1() var pat=new Parent1() console.log(chi.constructor) //Child console.log(pat.constructor) //Parent
因此,綜合以上,這總方式纔是最完美的!!
題目1:什麼是同源策略以及限制
同源策略:同一個源才能交互,一個源包含三部分的內容,協議,域名還有端口號,這三個必須徹底同樣,纔是同一個源
限制:
1) Cookie,LocalStorge和IndexDB沒法讀取
2) DOM沒法得到
3) AJAX請求沒法發送
題目2:先後端如何通訊
Ajax WebScoket CORS
題目3:如何建立ajax
var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange(function() { if (xmlhttp.readyState == 4) { if (xmlhttp.status >= 200 && xmlhttp.status < 300 || xmlhttp.status = 304){ alert(xmlhttp.responseText) } } }) xmlhttp.open('GET', 'url', trur) xmlhttp.send(null)
考察 XMLHttpRequest對象的工做流程 ,兼容性處理 事件的觸發條件 事件的觸發順序