Skip to main content

JS基础

番风Less than 1 minute

面试官:说说var、let、const之间的区别 | web前端面试 - 面试官系列open in new window

  • 变量提升
  • 暂时性死区
  • 块级作用域
  • 重复声明
  • 修改声明的变量

面试官:ES6中数组新增了哪些扩展? | web前端面试 - 面试官系列open in new window

  • [...[1,2,3]]
  • Array.from(),Array.of()
  • flat(),flatMap()

面试官:对象新增了哪些扩展? | web前端面试 - 面试官系列open in new window

手写 instanceOf

const instanceof_ = function (A, B) {
	if (typeof A !== 'object' || A === null || typeof B != 'function') {
		return false;
	}
	const prototype = B.prototype;
	let __proto__ = A.__proto__;
	while (true) {
		if (__proto__ === null) {
			return false;
		}

		if (prototype === __proto__) {
			return true;
		}

		__proto__ = __proto__.__proto__;
	}
};
class Person {
	constructor() {
		this.a = 123;
	}
}
let b = new Person();
console.log(instanceof_(b, Person)); //true
console.log(b instanceof Person); //trues