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 need a way to convert functions too, any ideas?
There is a toString() method for functions in firefox, but how to make that work with json2.js?
Stringify a JavaScript Object Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);
Convert Object to String in java using toString() method of Object class or String. valueOf(object) method. Since there are mainly two types of class in java, i.e. user-defined class and predefined class such as StringBuilder or StringBuffer of whose objects can be converted into the string.
The answer is option D (str(x)). str(x) converts the object to a string in python.
Object properties can be both primitive values, other objects, and functions. An object method is an object property containing a function definition. JavaScript objects are containers for named values, called properties and methods.
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/
Use String() function http://www.w3schools.com/jsref/jsref_string.asp
var f = function(a, b){ return a + b; } var str = String(f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With