
面试收录
无知的圆
这个作者很懒,什么都没留下…
展开
-
【奇怪的输出题】对象引用的问题
题目如下: var a = {n: 1}; var b = a; a.x = a = {n: 2}; console.log(a.x) console.log(b.x) 答案是: undefined {n:2} 解析: 首先:a和b同时引用了{n:2}对象 然后执行a.x = a = {n: 2}语句,尽管赋值是从右到左的 但.的优先级比=高,所以这里会先执行a.x,相当于为a所指向的对象{n:1}新增了一个属性x 然后执行a={n:2},相当于改变了a的指向,a不再指向对象{n:1},而原创 2021-08-20 21:16:25 · 257 阅读 · 0 评论 -
【记面试遇到的坑】 对象使用数组的push方法后会发生什么?
奇怪的面试题 最近碰到一道奇奇怪怪的面试题,对象使用数组的push方法后会发生什么?题目如下: var obj = { '2':3, '3':4, 'length':2, 'splice':Array.prototype.splice, 'push':Array.prototype.push } obj.push(1) obj.push(2) obj.push(3) console.log(obj); 求最后打印出的的obj是什么? 答案是: { '2原创 2021-08-19 19:12:46 · 581 阅读 · 0 评论