使用数据序列化功能

时间:2016-11-06 08:44:13

标签: node.js serialization

我试图尝试使用系统来序列化附加数据的函数。

我有这个,但它没有(预)用Node编译,任何人都知道什么是错的?

function outerOuter() {

  return (function outer (foo, bar, baz) {     // foo, bar, and baz are injected JSON strings

    return function yourSerializedFunction () {

      //foo, bar, and baz are available here, but you need to call JSON.parse on them

    }

  }(
    '{"foo":"is-serialized"}',
    '{"bar":"is-serialized"}',
    '{"baz":"is-serialized"}',
  ));

}

console.log(outerOuter().toString());

如果你能做我想做的事,也许你可以帮助弄清楚出了什么问题:)

1 个答案:

答案 0 :(得分:0)

信不信由你,这就是参数列表中的尾随逗号,这有效:

function outerOuter () {

  return (function outer (foo, bar, baz) {     // foo, bar, and baz are injected JSON strings

    return function yourSerializedFunction () {

      //foo, bar, and baz are available here, but you need to call JSON.parse on them

    }

  })(
    '{"foo":"is-serialized"}',
    '{"bar":"is-serialized"}',
    '{"baz":"is-serialized"}'
  );

}

console.log(outerOuter.toString());