getElementsByTagName返回的类数组对象的属性是不可写的,但是是活的对象。因此对getElementsByTagName返回的对象做了如下测试。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
window.onload=function () {
var divs=document.getElementsByTagName("div");
var mydiv=document.createElement("div");
mydiv.innerHTML="ahhaha";
console.log(Object.getOwnPropertyDescriptor(divs.__proto__,"length"));
console.log(Object.getOwnPropertyDescriptor(divs,"0"));
console.log(divs.length);
divs[0]=mydiv;
console.log(divs.length);
console.log(divs[0].innerHTML);
}
</script>
<title>Title</title>
</head>
<body>
<div>dsfe<strong>dsfe<span>dfe</span></strong></div>
<div>dsfe<strong>dsfe<span>dfe</span></strong></div>
<div>dsfe<strong>dsfe<span>dfe</span></strong></div>
<div>dsfe<strong>dsfe<span>dfe</span></strong></div>
<div>dsfe<strong>dsfe<span>dfe</span></strong></div>
<div>dsfe<strong>dsfe<span>dfe</span></strong></div>
</body>
</html>
getELementsByTagName返回的对象的属性是不可写的,上述代码也验证了,但是测试该对象属性的特性时,返回的结果如下:
Object
configurable: true
enumerable: false
value: div
writable: true
proto: Object
writable特性为true,这一点很疑惑。