0
Hello
I have a function that returns an Object with several functions inside, I need this object to be returned as string, but when I do the JSON.stringfy() it returns an empty object.
Can someone help me!
Follow the Code below:
function run() {
var start = ({
"dinamico": function(opcao, params) {
var options = {
quickplies: (function(params){
var dinamico = {
"type": "application/vnd.lime.select+json",
"content":{
"scope":"immediate",
"text": params.title,
"options": params.options
}
}
return dinamico
})(params)
}
return options[opcao]
}
})
return JSON.stringify(start)
}
var funcoes = run();
console.log(funcoes)
JSON.stringify
does not serialize functions (its objectstart
has only one property, which is a function). Thus, since JSON does not support functions, it will not be "placed" in the output ofJSON.stringify
.– Luiz Felipe
Edith your question to remove the code in image. Put the formatted code as text between
\
```. As you can see here, post code as image nay is a good practice on this site.– Luiz Felipe
there is some way to export an object with functions inside as string?
– Jailson de Souza
Maybe this? Turn function into String with Javascript
– Luiz Felipe
It even exists, but the reverse conversion can open up a relatively serious security breach (XSS). I would avoid this as much as possible. Why do you want to serialize the object?
– bfavaretto
I am using blip to build chat bots, in it it is possible to create dynamic content such as carousel images menu etc.. i want to leave a global object exposed so that when I need to create some of these contents I just call the specific function of that object.
– Jailson de Souza