- 博客(6)
- 收藏
- 关注
原创 js对象的属性配置
Object.getOwnPropertyDescriptor(),返回对象对应属性的 属性配置; let obj = { name: '小明' } let mes = Object.getOwnPropertyDescriptor(obj, 'name') console.log(mes) /* configurable: true enumerable: true value: "小明" writable: true __proto__: Object */ co
2021-02-03 22:02:01
649
原创 apply call和bind
let lisi = { name: '李四' } let wangwu = { name: '王五' } function User(height, age) { console.log(`${this.name+age}岁${height}`) } User.call(lisi, '190cm', 11) User.apply(wangwu, ['189cm', 19]) 结果 apply 和 call 可以改变函数的this ,apply的第二个参数
2021-02-02 02:08:45
131
原创 构造函数不能使用return
function User(name) { this.name = name; } let xiaoming = new User('xiaoming'); console.log(xiaoming) 运行结果 function User(name) { this.name = name; return {}; } let xiaoming = new User('xiaoming'); console.log(xiaoming) 运行结果 使用retu
2021-02-02 01:44:03
1159
原创 WeakMap和WeakSet 的特点
WeakMap 的key必须是 对象类型,WeakSet 只有value没有key 并且value必须是 对象类型。 WeakMap和WeakSet都是弱引用的 let a = new WeakSet(); let b = {}; a.add(b); b = null; console.log(a); 打印结果 弱引用:引用了对象,对象的引用计数器不会增加。回收对象时,不需要考虑WeakMap和WeakSet是否引用了这个对象。WeakMap和WeakSet 因此也不提供任何可访问数
2021-02-01 23:16:12
177
原创 类数组一些东西
1.获取dom元素对象产生的类数组 let divs = document.getElementsByTagName('div'); console.log(divs);// HTMLCollection(5) [div, div, div, div, div] console.log([...divs]); //[div, div, div, div, div] 把类数组转化为数组 for (let i of divs) { cons
2020-12-04 17:52:08
104
原创 iterator接口 for of
原生具备Iterator接口的数据结构如下: Array2) Map3) Set4) String5) TypedArray6) 函数的argument对象,类数组 具有iterator接口的数据可以使用for… of循环和 …操作符
2020-12-04 01:08:53
141
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅