下面 是一个数组的扩展,怎么不行啊,难道是浏览器的问题吗?还是我的问题?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
Array.prototype._summ=Array.prototype.summ
(Array.prototype.summ=function(){
var _n=0;
for(var i in this){
if(this[i]=parseFloat(this[i])){
_n+=this[i];
//如果数组元素是数字则累加
} };
return _n;
});
Object.prototype.summ=Array.prototype._summ
var c=[3,2,32,32];
alert(c.summ());
</script>
</head><body>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
Array.prototype._summ=Array.prototype.summ
(Array.prototype.summ=function(){
var _n=0;
for(var i in this){
if(this[i]=parseFloat(this[i])){
_n+=this[i];
//如果数组元素是数字则累加
} };
return _n;
});
Object.prototype.summ=Array.prototype._summ
var c=[3,2,32,32];
alert(c.summ());
</script>
</head><body>
</body>
</html>
Array.prototype._summ=Array.prototype.summ
Array.prototype.summ=function(){
var _n=0;
for(var i in this){
if(this[i]=parseFloat(this[i])){
_n+=this[i];
//如果数组元素是数字则累加
} };
return _n;
};
Object.prototype.summ=Array.prototype._summ
var c=[3,2,32,32];
alert(c.summ());
</script>
Array.prototype.summ = function() {
var _n = 0;
for (var i in this) {
if (this[i] = parseFloat(this[i])) {
_n += this[i];
//如果数组元素是数字则累加
}
};
return _n;
};
var c = [3, 2, 32, 32];
alert(c.summ());
</script>
其他的代码都没用