"push" 在 Chrome DevTools-Console 的评估中意味着什么?
What does "push" mean in evaluation of Chrome DevTools-Console?
当我在 Chrome DevTools - Console 中评估一个特定变量时,结果如下:
(3) [Array(2), Array(2), Array(2), push: ƒ]
我知道 f 的意思,数组包含一个函数。
push 这个词在这个上下文中代表什么?
表示有人在数组中添加了自定义的属性。这不是标准 Array.prototype.push
,而是其他东西。
const arr = [1, 2];
arr.push = () => 'some custom implementation';
console.log(arr);
如果存在标准 .push
,它就不会出现在控制台中。
(在专业代码中尽量避免这种情况,很奇怪。)
当我在 Chrome DevTools - Console 中评估一个特定变量时,结果如下:
(3) [Array(2), Array(2), Array(2), push: ƒ]
我知道 f 的意思,数组包含一个函数。
push 这个词在这个上下文中代表什么?
表示有人在数组中添加了自定义的属性。这不是标准 Array.prototype.push
,而是其他东西。
const arr = [1, 2];
arr.push = () => 'some custom implementation';
console.log(arr);
如果存在标准 .push
,它就不会出现在控制台中。
(在专业代码中尽量避免这种情况,很奇怪。)