λJSONJSON 替代
λJSON 是 JSON 的嵌入式替代品,它可以让你解析和字符串化纯函数及其内容。
示例代码:
var LJSON = require("LJSON");// `newPlayer` is a function and couldn't be serialized with JSON.function newPlayer(name){ return {
name : name,
hp : 12,
atk : 5,
def : 5,
inventory : []}
};
// LJSON has no trouble doing it because `newPlayer` is pure.
var newPlayerSource = LJSON.stringify(newPlayer);
var John = LJSON.parse(newPlayerSource)("John");console.log("Serialized λJSON: " + newPlayerSource);console.log("Parsed and applied: " + John);评论
