length 属性的属性描述符对象显示为 configurable: true、writable:true 和 enymerable:true 但它的行为类似于只读。
我知道只读特性只能通过PDO(property descriptor object)来实现。
有人可以提供任何线索吗? 这怎么是只读的?
var nodeList = document.getElementsByName('demo');
nodeList.length; //3
nodeList.length = 6;
nodeList.length; //3
Object.getOwnPropertyDescriptor(nodeList,'length')
Object
configurable: true
enumerable: true
value: 3
writable: true
__proto__: Object
最佳答案
length
是只读的,根据 http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-536297177
确实,display 是一种误导,但那是因为它是一个宿主对象,所以它不必像我们习惯的那样表现得像 native 对象。不过,这值得提交错误报告,因为显示应该尽可能地匹配行为,尤其是在这种明显的情况下。
关于javascript - NodeList对象的length属性只读,如何验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14627786/