prototype对数组的扩展和for语法造成冲突怎么解决?

qq1480801 2010-04-27 06:17:00
http://v.9-so.com/goods.php?id=8
这是目前测试的地址

网站原系统是ecshop的

现在模板里加了几个js文件
里面的main.js只要一加上就会和ecshop中的transport.js有冲突...


而刚才在其它帖子中有人提到解决方法为
"prototype对数组的扩展和你的for(i in array)语法造成冲突。"
听说是解决了,请问有哪位高手能够指教下如何处理?
...全文
80 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq1480801 2010-04-27
  • 打赏
  • 举报
回复
啊啊啊啊...有没有高手帮忙解决下啊?????????/


跪求解决........
qq1480801 2010-04-27
  • 打赏
  • 举报
回复
Object.prototype.toJSONString = function () {
var a = ['{'], // The array holding the text fragments.
b, // A boolean indicating that a comma is required.
k, // The current key.
v; // The current value.

function p(s) {

// p accumulates text fragment pairs in an array. It inserts a comma before all
// except the first fragment pair.

if (b) {
a.push(',');
}
a.push(k.toJSONString(), ':', s);
b = true;
}

// Iterate through all of the keys in the object, ignoring the proto chain.

for (k in this) {
if (this.hasOwnProperty(k)) {
v = this[k];
switch (typeof v) {

// Values without a JSON representation are ignored.

case 'undefined':
case 'function':
case 'unknown':
break;

// Serialize a JavaScript object value. Ignore objects that lack the
// toJSONString method. Due to a specification error in ECMAScript,
// typeof null is 'object', so watch out for that case.

case 'object':
if (this !== window)
{
if (v) {
if (typeof v.toJSONString === 'function') {
p(v.toJSONString());
}
} else {
p("null");
}
}
break;
default:
p(v.toJSONString());
}
}
}

// Join all of the fragments together and return.

a.push('}');
return a.join('');
};


这是ECSHOP本身那段JS的报错代码
标记红色的就是报错位置.
这个咋写?
passself 2010-04-27
  • 打赏
  • 举报
回复
用别的循环来,直接用for(var i=0;i<xx;i++)这样冲突吗?这样还是冲突的话,那在引入prototype.js之前循环

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧