谁能告诉我这个函数的用图
一面的这段代码是transport.js 文件中的,因为这段代码会同其它的JS有冲突,删除它问题就解决了,但是因为不知它的用途,所以不敢乱改。希望得各位大侠的指点代码位于transport.js 的587行至642行,如下:
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 (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('');
};
在百度找了很多资料,说到 Javascript: 避免使用Object.prototype
原文:
[url]http://benlee.tw/blog/?p=277[/url]
如果真如这文章中所说的要避免使用,但不知这段要如何改才行
回复 #1 tianbolue 的帖子
Transport 用于支持AJAX的传输类~~删除了你整个站都会有问题 请问会跟哪个有冲突? 我把有冲突的JS发上来给你看看,在附件的allcatepop_c.js这个文件的第798行和799行冲突这四个JS文件的作用是做弹出菜单的
效果可以到我的网站看,把鼠标放到“蛋糕分类”就可以看到这个效果了
[url=http://www.cnyummy.com]www.cnyummy.com[/url]
这个网站是SHOPEX做的,现在想转成ECSHOP
[[i] 本帖最后由 tianbolue 于 2007-12-13 00:17 编辑 [/i]] 希望得到解答 自己顶一下 是因为你自己的JS程序调用了onload事件 与我们程序本身的onload发生了冲突
如果你想继续使用这段JS代码 那就必须重新把事件作调整 会跟 mootool 1.11 冲突 也是 prototype.toJSONString 这个转换函数的问题
页:
[1]
