3 ms·
You wouldn't be able to do the JSON stuff and the string wrapping with a single function, but otherwise that could be a good idea.
by plorkyeran 14y ago
You wouldn't be able to do the JSON stuff and the string wrapping with a single function, but otherwise that could be a good idea.
- Mahn 14y agoWhy not? You could test if the string is valid json, and if it is do object wrapping, otherwise do string wrapping. This method is used often in jQuery, figuring out what to do depending on what you pass to it. EDIT: and I guess a second, optional argument to force a specific data type could be added for those rare cases where you have a json string and you want to run string functions on it.