Subj : implementing sprintf in Javascript To : netscape.public.mozilla.jseng From : Jason Date : Mon Feb 21 2005 01:57 pm hmm, in searching the archives this (creating a Javascript-accessible sprintf) has come up several times (there was one posting 6/11/2001 labeled "JS-eng Tricks"), but I couldn't find anything that looked like a good bulletproof solution. has anyone who would be willing to share their implementation done this in a robust manner? The thread I referenced above constructed a va_list, used vsprintf, & only supported INT and STRING types (leaving out double/float). Seems like the caveat here is that both the C *printf functions and the functions in jsprf.c assume correct matching of args & format parameters & don't error-check. (are JS_vsmprintf & the other functions in jsprf.c formal JSAPI functions or is it one of the helper functions in SpiderMonkey subject to change? They're not listed in the API docs http://www.mozilla.org/js/spidermonkey/apidoc/sparse-frameset.html) At least two issues here: (1) resolving valid conversion of datatypes e.g. sprintf("%d %f",3,3) (2) dealing with boneheaded mistakes w/o crashing e.g. sprintf("%s",42); My guess is that for either of these, you'd have to explicitly look over the format string and cast JSVAL args appropriately (or throw an error), then either hand them to one of the sprintf functions or manually implement the printf itself (bleah.) .