📜  json-parsejson-stringifyx-purpose - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:40.906000             🧑  作者: Mango

代码示例1
It's a way of cloning an object, so that you get a complete copy that is unique but has the same properties as the cloned object.

var defaultParams = { a : 'b' };
var params = JSON.parse(JSON.stringify(defaultParams));

console.log( params.a ); // b
console.log( defaultParams.a ); // b
console.log( params === defaultParams ); // false
The above outputs false because even though both objects have the a property, with the value b, there are different objects that are independent of each other (they don't refer to the same reference).

The JSON method will only work with basic properties - no functions or methods.