2016-11-06 33 views
-1

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

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

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()); 

如果你能什么,我试图做的,也许你可以帮助找出什么是错的:)

回答

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()); 
+1

我一直在寻找特定逗号,我想naaah ..然后发现自己在看https://www.npmjs.com/package/node-serialize .. – Xorifelse

+0

是的,我花了一段时间的数字, out –

+0

是的,使用上面的方法你应该能够序列化所需的函数通常通过闭包获得的数据,但是你不知何故需要将这些数据以字符串的形式存储,这很棘手,但它可以完成 –