忆车科技——

  • css 选择符有哪些?那些属性可以继承?优先级算法如何计算?内联和 !important 哪个优先级高?

    1. 选择符:id 选择器,class 选择器, 伪类选择器, 伪元素选择器, 标签选择器, 通配符选择器, 后代选择器
    2. 可以继承的属性: font-size font-family color
    3. 不可以继承的有: border padding margin background-color width height等
    4. !important: infinity, 行内元素: 1000, id: 100, class|属性|伪类: 10, 标签|伪元素: 1, 通配符: 0
    5. !important 优先级最高
  • 行内元素有哪些?块级元素有哪些?css 的盒模型有哪些?

    1. 行内元素:span, i, b, img, a
    2. 块级元素:p, div, form, body, ul, ol, h1-h6, hr
    3. 盒模型: w3c 标准盒模型 content-box ie 怪异盒模型 border-box
  • 如何垂直居中

    1. line-height = height
    2. position: absolute; top: 50%; transform: translateY(-50%)
    3. 弹性盒子, display: flex; align-items: center;
    4. vertical-align: middle;
  • 请描述一下 cookie, sessionStorage, localStorage 的区别

    • 四点:一、是否可以与浏览器进行交互。 二、存储空间的大小。 三、存储时长的限制。 四、是否可以被访问
    1. cookie 可以存储的内容比较少,可以很方便的向后台传值,灵活的设置存储时间,可以在同源的浏览器窗口中共享
    2. sessionStorage 存储的内容稍多,每次关闭窗口后自动清楚存储的数据,存储的数据不会发送,不能在其他浏览器窗口中访问。
    3. localStorage 存储的内容稍多,可以长期的存储数据,存储的数据不会发送出去,可以在同源的浏览器窗口中共享
  • call、apply、bind 的区别

    • 传参形式的区别:

      1. call 传递参数第一个参数为要绑定的 this, 剩余的参数可以传多个
      2. apply 只能传递两个参数 第一个参数为要绑定的 this,第二个传入参数
      3. bind 只能传递一个要绑定的 this
    • 绑定方式不同

      1. call 和 apply 是在调用函数执行的时候使用,例 test()test.call() test.apply()
      2. bind 可以有多种绑定方式 test().bind() test.bind(this)() var str = test.bind() str();
    • 作用方式不同

      1. call 和 apply 直接执行一个函数,并将里面的 this 替换成为了传入的 this
      2. bind 将 this 传入,并返回一个新的绑定了新的 this 的函数,而且 this 不可以被更改
  • 在 javascript 中什么是伪数组?如何将伪数组转换为标准数组

    1. 按照索引排序的
    2. 具有 length 属性
    3. 没有数组的 push pop shift 等方法
      将伪数组转换为标准数组: Array.prototype.slice.call() 或者 Array.form()
  • 实现一个深克隆函数
  1. function deepClone(origin, target){
  2. var target = target || {};
  3. var toStr = Array.prototype.toString;
  4. var strArr = '[object Array]';
  5. for(var prop in origin){
  6. if(origin.hanOwnProperty(prop)){
  7. if(origin[prop] !== null && typeof(origin[prop]) == 'object'){
  8. target[prop] = toStr.call(origin[prop]) === strArr ? [] : {};
  9. deepClone(origin[prop], target[prop]);
  10. }else{
  11. target[prop] = origin[prop]
  12. }
  13. }
  14. }
  15. return target
  16. }
  • 实现一个函数,给定一个非负数整数 num,反复将各个位上的数字相加,直到结果为一位数。
  1. function addDigits(num){
  2. if(!num){
  3. return null
  4. }
  5. const str = num.toString();
  6. let res = 0;
  7. for (let i = 0; i < str.length; i++) {
  8. res += +str.substring(i, i + 1)
  9. }
  10. if(res.toString().length === 1){
  11. return res
  12. }else{
  13. return addDigits(res)
  14. }
  15. }
  16. console.log( addDigits(546) ) // 6 因为 5 + 4 + 6 = 15 => 1 + 5 = 6