【发布时间】:2012-05-30 13:13:44
【问题描述】:
为什么 JSON.stringify() 不显示 prop2?
var newObj = {
prop1: true,
prop2: function(){
return "hello";
},
prop3: false
};
alert( JSON.stringify( newObj ) ); // prop2 appears to be missing
alert( newObj.prop2() ); // prop2 returns "hello"
for (var member in newObj) {
alert( member + "=" + newObj[member] ); // shows prop1, prop2, prop3
}
JSFIDDLE:http://jsfiddle.net/egret230/efGgT/
【问题讨论】:
-
@BrandtSolovij:函数就是对象:尝试运行
(function() {}) instanceof Object
标签: javascript json function object stringify