var person = { firstName: "Ben", lastName: "Bitfiddler" };
person.toString = function() {
return this.firstName + " " + this.lastName;
}
print(person); // prints "Ben Bitfiddler"
| * | thing1 | any javascript type |
| * | thing2 | any javascript type |
| * | etc | ... |
| * | thing1 | any javascript type |
| * | thing2 | any javascript type |
| * | etc | ... |
- %d - an integer
- %f - a floating-point number
- %b - a boolean
- %s - a string
Each time one of these "slot" appears in your format string, the next argument is displayed according to the type of slot you specified.
AppJet supports Java's specification of printf, which has a ton of features, including selecting arguments out of order, formatting dates and times, and specifying how many characters wide each slot should be.
| string | formatString | |
| * | arg1 | |
| * | arg2 | |
| * | arg3 | ... |
var x = 5;
printf("an integer: %d", x);
printf("Two strings: [%s] and [%s].", "string one", "string two");
| string | formatString | |
| * | arg1 | |
| * | arg2 | |
| * | arg3 | ... |
var result = sprintf("%f", Math.sqrt(2));
print("The square root of two, as a string, is: ", result);
(Inspired by http://javascript.crockford.com/remedial.html)
| object | data | dictionary of values |
| string | str |
| string | str with keys of data replaced by their values |
var data = {name: "Aaron", age: 25, today: new Date()};
print(supplant(data, """
{name}'s age is {age} years, as of {today}.
"""));
Normally, printing a string will cause it to be translated so that it appears the same on the screen as it did in your code. If you're writing your own HTML, you don't want it to be processed this way. Wrapping a string in html(...) by-passes normal printing behavior, so that print(html(" -- html goes here ---")) will write the HTML directly to the page.
If you want to make use of print(...)'s machinery for translating things into HTML, you can call toHTML(...) on an object and use the result in your raw code.
| string | text | the raw text |
| object | an object which, when printed, prints the raw html text |
print(html("""
<br />
<br />
<div><p>Here is some text inside a P inside a DIV.</p>
</div>
<br />
"""));
The raw() function is deprecated. Now use the html() function instead. (It does the same thing).
| text |
You can control how toHTML(...) (and therefore print(...)) behave on an object by giving that object a .toHTML() function.
| * | x | any javascript variable |
| string | html-formatted string |
| string | url | an absolute or relative URL to link to |
| string | optionalText? | the text of the link, defaults to the url if absent |
print(link("http://appjet.com"));