面試記錄2

面試記錄2

1. Ajax的原理,和進程相關

2. 進程和線程的關係

進程和線程的區別css

3. css選擇器的優先級

  1. 不一樣級別

!important > 行內樣式>ID選擇器 > 類選擇器 > 標籤 > 通配符 > 繼承 > 瀏覽器默認屬性html

  1. 相同級別

後面覆蓋前面的html5

4. 閉包相關

閉包的做用:面試

  • 在函數外部讀取函數內部局部變量;
  • 在函數外部讀取函數內部局部變量,變量被封裝到局部做用域,只提供接口獲取該變量,就像傳統oop的私有變量,公有方法同樣,這樣能夠避免污染全局變量;
  • 讓這些值始終保存在內存中。

使用場景瀏覽器

  • 因爲setTimeout方法不能傳遞參數,能夠用閉包來解決
function func(param) {
        return function() {
            alert(param);
        }
    }
    var f = func(1)
    setTimeout(f, 1000);
  • 節流函數
function debounce(func, delay) {
        let timer;
        //該函數是一個閉包,因此timer會一直存在於內存中,而且timer只能在函數內部訪問
        return function (...args) {
            if (timer) {
                clearTimeout(timer);
            }
            timer = window.setTimeout(() => {
                func.apply(this, args);
            }, delay);
        }
    }

5. html5新特性

  • Canvas Api
  • <audio> <vedio>
  • Geolocation Api
  • Websocket Api
  • Form Api
  • Storage Api
  • 離線應用

6. 垂直居中

垂直居中
用彈性盒子實現水平垂直居中閉包

<div class="parent">
  <div class="children">我是經過flex的水平垂直居中噢!</div>
</div>
html,body{
  width: 100%;
  height: 200px;
}
.parent {
  display:flex;
  align-items: center;/*垂直居中*/
  justify-content: center;/*水平居中*/
  width:100%;
  height:100%;
  background-color:red;
}
.children {
  background-color:blue;
}

7. Promise

兩個做用app

  1. 避免回調地獄
  2. 爲了咱們的代碼更加具備可讀性和可維護性,咱們須要將數據請求與數據處理明確的區分開來

8. alert(1&&2) alert(1||2)

alert(1 && 2)  //2 括號裏面先計算,var a = 1 && 2; alert(a)
alert(1 || 2)  //1 括號裏面先計算,var a = 1 || 2; alert(a)

9. display: none 和 visibility:hidden

display:none //隱藏元素,不佔據文檔流
visibility:hidden   //隱藏元素,不佔據文檔流

10. 對象先會先找自身的屬性,而後再去找原型上的屬性

function C1(name) {
    if (name) this.name = name;
};
C1.prototype.name = 'weilei';
console.log(new C1().name);  // weilei

function C2(name) {
    this.name = name;
};
C2.prototype.name = 'weilei';
console.log(new C2().name);  // undefined

function C3(name) {
    this.name = name || 'sam';
};
C3.prototype.name = 'weilei';
console.log(new C3().name);  // sam

11. mouseover和mouseenter區別

惟一的區別是 onmouseenter 事件不支持冒泡socket

12. js改變html的title

document.title = 'xxx'
相關文章
相關標籤/搜索