Subj : Re: define new function in Class String (Spidermonkey) To : netscape.public.mozilla.jseng From : Blaubaer Date : Wed Jan 05 2005 08:30 am Sorry, for bugging you. But I want to understand this engine, but it is hard to understand for a small programmer. I learning by doing with some faults. I know. But I use the sprintf function in some C++ String classes like: AnsiString a; a.sprintf("I'am to small with %d!", 1); ShowMessage(a); ....I miss this function and want to implement it. sprintf in global object is like C and not like C++ or Java, when I want to use it for a "String". Last chance: "poor-man's namespace" :-( Thx Blaubaer "Brendan Eich" schrieb im Newsbeitrag news:41DB90A5.6000703@meer.net... > Blaubaer wrote: >> I want to add the function sprintf to the String type. >> var a = new String(); >> a.sprintf("Integer: %d", 1); >> >> My function sprintf works, an returns the result, but I also want to >> change the value of "a". > > > That's wastefully expressed. Strings are not objects in JS (string is a > primitive type: typeof "hi" == "string", typeof new String("hi") == > "object"). It requires var a = new String() before the guts of the idea, > for no purpose. > > It would be better to make a global sprintf function, or if you want to > put it in a poor-man's namespace, make it a static: String.sprintf. > > /be .