Convert Javascript Object (incl. functions) to String

后端 未结 10 1059
你的背包
你的背包 2020-12-29 21:35

Hey, Im trying to convert specific javascript objects to a String. So far I\'m working with json2.js. As soon as my Object contain functions, those functions are stripped. I

10条回答
  •  猫巷女王i
    2020-12-29 21:52

    Actually, I think it is possible and easy. At least when doing jsonP with nodeJS it works for me just fine, and it's demonstratable by the following fiddle. I did it by simply adding strings to a function:

    var anyString = '';
    var aFunction = function() { return true; };
    var functionToText = anyString + aFunction;
    console.log(functionToText);
    

    here's the fiddle: http://jsfiddle.net/itsatony/VUZck/

提交回复
热议问题