2016-11-06 63 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

是的,使用上面的方法你應該能夠序列化所需的函數通常通過閉包獲得的數據,但是你不知何故需要將這些數據以字符串的形式存儲,這很棘手,但它可以完成 –