We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
输出以下代码执行的结果并解释为什么?
var obj = { '2': 3, '3': 4, 'length': 2, 'splice': Array.prototype.splice, 'push': Array.prototype.push } obj.push(1) obj.push(2) console.log(obj) // obj = [empty, empty, 1, 2, length: 4, splice: f, push: f]
push 是特意设计为通用的,Array.prototype.push 可以在一个对象上工作
var obj = { length: 0, addElem: function addElem (elem) { [].push.call(this, elem); } }; obj.addElem(1); obj.addElem(2); console.log(obj.length); // obj = {0: 1, 1: 2, length: 2, addElem: f}
push 方法根据 length 属性来决定从哪里开始插入给定的值
var obj = { length: 1, addElem: function addElem (elem) { [].push.call(this, elem); } }; obj.addElem(1); obj.addElem(2); console.log(obj.length); // obj = {1: 1, 2: 2, length: 3, addElem: f}
最后结果输出的是一个伪数组,如何判断伪数据?
/** * @param {?Object} obj * @return {boolean} */ function isArrayLike(obj) { if (!obj || typeof obj !== 'object') return false; try { if (typeof obj.splice === 'function') { const len = obj.length; return typeof len === 'number' && (len >>> 0 === len && (len > 0 || 1 / len > 0)); } } catch (e) { } return false; }
输出以下代码执行的结果并解释为什么
The text was updated successfully, but these errors were encountered:
sihai00
No branches or pull requests
伪数组和push方法
输出以下代码执行的结果并解释为什么?
push
push 是特意设计为通用的,Array.prototype.push 可以在一个对象上工作
push 方法根据 length 属性来决定从哪里开始插入给定的值
伪数组
最后结果输出的是一个伪数组,如何判断伪数据?
参考
输出以下代码执行的结果并解释为什么
The text was updated successfully, but these errors were encountered: