console
All console
methods are available as stache helpers. A few of these are shown below, but any method available on the global console can be called from stache.
{{console.log([EXPRESSION])}}
Uses console.log
to show the result of the provided expressions.
import {stache} from "can";
const view = stache(`{{ console.log(person.name, 'is', person.age, 'year(s) old') }}`);
view( {
person: {
name: "Connor",
age: 1
}
} );
This will log to the console:
Connor is 1 year(s) old
You can also use console.info
, console.warn
, console.error
in the same way.
console.time / console.timeEnd
console.time() and console.timeEnd() can be used to track how long an operation takes to run:
import {stache} from "can";
const view = stache( `
{{console.time("rendering list")}}
<ul>
{{#for(thing of this.things)}}
<li>{{thing}}</li>
{{/for}}
</ul>
{{console.timeEnd("rendering list")}}
` );
view( {
things: [ "hammer", "apple", "dog" ]
} );
This will log something like this to the console:
rendering list: 5.56298828125ms
console.table
import {stache} from "can";
const view = stache( "{{console.table(this.things)}}" );
view( {
things: [ "hammer", "apple", "dog" ]
} );
This will log something like this to the console:
(index) | Value |
---|---|
0 | "hammer" |
1 | "apple" |
2 | "dog" |