- 博客(2)
- 收藏
- 关注
原创 js 判断数组的五种方式
const arr = []; const obj = {}; // 1. instanceof 检测构造函数的 prototype 属性是否出现在某个实例对象的原型链上 console.log(arr instanceof Array); // true console.log(obj instanceof Array); // false // 2. constructor 实例的 constructor指向构造函数 console.log(arr.constructor === Array); /
2021-05-17 18:11:18 72 1
原创 js new做了什么,怎么去仿写new
// 假设你在学习之前了解 js面向对象 function Student(name){ this.name = name; } const stu = new Student("Tom"); // 当我们通过构造函数 new 一个实例时都做了什么? 1. 创建一个新对象 2. 将新对象的 __proto__ 指向构造函数的 prototype //(所以实例可以使用构造函数上的属性和方法) 3. 将构造函数的 this 指向这个新对象 4. 返回新对象
2021-04-03 19:38:06 126
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人