测试总结

135 阅读2分钟

测试总结

题目一
function test (a, b) {
    arguments[2] = 3;
    console.log(arguments.length);
    console.log(arguments[2]);
}

test(1, 2);

console.log(test.length);
  • 考点
    • 类数组(伪数组),对象,arguments
  • 理解
    • 类数组是对象,不具备数组的特性,所以当你 obj[2]的时候相当于obj.2 她只是给对象加了个属性,而length 也是这个对象的属性,没有更改length所以这个length不会改变
题目二
const obj = {
    '2': 3,
    '3': 4,
    push: Array.prototype.push
}

obj.push(1);

console.log(obj.length);
// ------------------------------
const obj = {
    '2': 3,
    '3': 4,
    length:2,
    push: Array.prototype.push
}

obj.push(1);

console.log(obj.length);
// 如果这个对象中有length 属性 如果继续 push  则会根据length的位置进行追加 
  • 考点
    • 基于类数组的改变,增加了数组方法push 方法的理解,length
  • 理解
    • 当这个对象具有 数组方法 当他push的时候如果对象中没有length这个属性则会默认给加一个,并且默认值为你push进去的长度
题目三
({} + (function () {console.log(123)})()).length
  • 考点
    • 引用类型进行相加后的隐士类型转换
  • 理解
    • 引用类型是不能相加的如果相加必然调用Object.prototype.toString,当对象调用toString的时候则会变成[object Object] 函数执行完毕返回的则是 undefined,每个函数都有一个return如果没有写则会在末尾自动return undefined
题目四
// reduce 手写
Array.prototype.myReduce = function (callBack, initialValue) {
    var arr = this,
        len = arr.length,
        arg2 = arguments[2];
    for (var i = 0; i < len; i++) {
        initialValue = callBack.apply(arg2, [initialValue, arr[i], i, arr])
    }
    return initialValue
}
  • 考点
    • reduce的理解,底层实现
  • 理解
    • reduce 他是一个归纳函数,但他跟遍历函数有所不同的是,它可以处理数组里的值并赋到 initialValue里去也就是第二个参数,他的第二个参数和回调中的第一个参数是一个,
题目五
严格模式
题目六
WeakMap
题目七
var const let 的区别
var 可以重复声明
let const 不可以重复声明 暂存死区
const 声明必须赋值
题目八
const test2 = () => {
  const t = () => {
    console.log(this);
  }
  t();
}

test2();
new test2();
// ------------------------------------------
const test2 = () => {
  test2.t = () => {
    console.log(this);
  }
  test2.t();
}

test2();
题目九
const test = (...args) => {
  console.log(args);
  console.log(arguments);
}
test();
题目十
;(function () {
    var c = 1;

    function Test () {
        console.log(c);
    }

    Test.prototype.a = function () {
        Test.b();
    }

    Test.b = function () {
        console.log('I am a static function of Test constructor');
    }

    window.Test = Test;
})();
题目十一
const promise = new Promise((resolve, reject) => {
    console.log(1);
    resolve();
    console.log(2);
})


promise.then(() => {
    console.log(3);
})


console.log(4);
题目十二
Promise 中reject 和 catch 处理上有什么区别
题目十三
let s = new Set();
s.add([1]);
s.add([1]);
s.add(1);
s.add(1);
console.log(s.size);