在Mozilla的文档说回报
undefined(而不是
"none"):
http://jsfiddle.net/userdude/rZ5Px/
function replacer(key,value){ if (key=="privateProperty1") return undefined; else if (key=="privateProperty2") return undefined; else return value;}var x = { x:0, y:0, divID:"xyz", privateProperty1: 'foo', privateProperty2: 'bar'};alert(JSON.stringify(x, replacer));
这是一种复制方法,以防万一您决定走那条路线(根据您的评论)。
http://jsfiddle.net/userdude/644sJ/
function omitKeys(obj, keys){ var dup = {}; for (var key in obj) { if (keys.indexOf(key) == -1) { dup[key] = obj[key]; } } return dup;}var x = { x:0, y:0, divID:"xyz", privateProperty1: 'foo', privateProperty2: 'bar'};alert(JSON.stringify(omitKeys(x, ['privateProperty1','privateProperty2'])));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)