1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        【前端面試】同學(xué),你會手寫代碼嗎?

        共 12566字,需瀏覽 26分鐘

         ·

        2020-02-09 23:23

        (給前端大學(xué)加星標,提升前端技能.

        作者:我不吃餅干呀

        https://juejin.im/post/5c9edb066fb9a05e267026dc

        【前端面試】?手寫代碼匯總:CSS & JS

        如果您發(fā)現(xiàn)錯誤,請一定要告訴我,拯救一個辣雞(但很帥)的少年就靠您了!


        CSS 部分

        兩欄布局

        要求:垂直兩欄,左邊固定右邊自適應(yīng)。

                        Document        
        1-left
        1-right
        2-left
        2-right
        3-left
        3-right
        4-left
        4-right

        三欄布局

        要求:垂直三欄布局,左右兩欄寬度固定,中間自適應(yīng)

                        Document        
        1-left
        1-middle
        1-right
        2-left
        2-middle
        2-right
        3-left
        3-right
        3-middle

        圣杯布局 和 雙飛翼布局

        和三欄布局要求相同,不過中間列要寫在前面保證優(yōu)先渲染。

                        Document            
        圣杯-middle
        圣杯-left
        圣杯-right
        雙飛翼布局-middle
        雙飛翼布局-left
        雙飛翼布局-right

        三角形

        實現(xiàn)一個三角形

        常見題目,通過 border 實現(xiàn)

          三角形    

        正方形

        使用 css 實現(xiàn)一個寬高自適應(yīng)的正方形

                                

        扇形

        實現(xiàn)一個 1/4 圓、任意弧度的扇形

        有多種實現(xiàn)方法,這里選幾種簡單方法(我看得懂的)實現(xiàn)。

                        Document        


        水平垂直居中

        實現(xiàn)子元素的水平垂直居中

          水平垂直居中    


        清除浮動

        要求:清除浮動

        可以通過 clear:both 或 BFC 實現(xiàn)

          清除浮動    

        彈出框

        使用 CSS 寫一個彈出框效果

                        Document        
        頁面內(nèi)容
        彈出框

        導(dǎo)航欄

        要求:一個 div 內(nèi)部放很多水平 div ,并可以橫向滾動。

                        Document        

        CSS 部分完,總結(jié),F(xiàn)lex 無敵。


        JavaScript 部分

        手寫 bind、call 和 apply

        Function.prototype.bind = function(context, ...bindArgs) {  // func 為調(diào)用 bind 的原函數(shù)  const func = this;  context = context || window;
        if (typeof func !== 'function') { throw new TypeError('Bind must be called on a function'); } // bind 返回一個綁定 this 的函數(shù) return function(...callArgs) { let args = bindArgs.concat(callArgs); if (this instanceof func) { // 意味著是通過 new 調(diào)用的 而 new 的優(yōu)先級高于 bind return new func(...args); } return func.call(context, ...args); }}
        // 通過隱式綁定實現(xiàn)Function.prototype.call = function(context, ...args) { context = context || window; context.func = this;
        if (typeof context.func !== 'function') { throw new TypeError('call must be called on a function'); }
        let res = context.func(...args); delete context.func; return res;}
        Function.prototype.apply = function(context, args) { context = context || window; context.func = this;
        if (typeof context.func !== 'function') { throw new TypeError('apply must be called on a function'); }
        let res = context.func(...args); delete context.func; return res;}

        實現(xiàn)一個繼承

        // 參考 You Dont Know JavaScript 上卷// 基類function Base() {}// 派生類function Derived() {    Base.call(this);}// 將派生類的原型的原型鏈掛在基類的原型上Object.setPrototypeOf(Derived.prototype, Base.prototype);

        實現(xiàn)一個 new

        // 手動實現(xiàn)一個 new 關(guān)鍵字的功能的函數(shù) _new(fun, args) --> new fun(args)function _new(fun, ...args) {    if (typeof fun !== 'function') {        return new Error('參數(shù)必須是一個函數(shù)');    }    let obj = Object.create(fun.prototype);    let res = fun.call(obj, ...args);    if (res !== null && (typeof res === 'object' || typeof res === 'function')) {        return res;    }    return obj;}

        實現(xiàn)一個 instanceof

        // a instanceof bfunction _instanceof(a, b) {    while (a) {        if (a.__proto__ === b.prototype) return true;        a = a.__proto__;    }    return false;}

        手寫 jsonp 的實現(xiàn)

        // foo 函數(shù)將會被調(diào)用 傳入后臺返回的數(shù)據(jù)function foo(data) {    console.log('通過jsonp獲取后臺數(shù)據(jù):', data);    document.getElementById('data').innerHTML = data;}/** * 通過手動創(chuàng)建一個 script 標簽發(fā)送一個 get 請求 * 并利用瀏覽器對 

        路由實現(xiàn) - history

          history 路由  
        首頁 個人中心頁 幫助頁

        還有一些稍復(fù)雜的可以寫,有時間再補。


        分享前端好文,點亮?在看?7c2cc4d5fe8191342d0a554e1d5177ec.webp

        瀏覽 44
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            黑人大屌在线 | 久久精品国产亚洲AV高清热看看 | 我和漂亮老师做爰8 | 腿快张开(双肉合集) | 免费日比视频 | 国产69视频在线观看 | 大操视频网站 | 男人日女人麻批 | 性荷兰videos艳星极品 | 亚洲色吧|