debugger
In development, breaks at the given point in the template to inspect the current scope in the console.
{{debugger}}
Breaks any time that part of the page renders.
The following will hit the debugger when you click the Show button:
<my-demo></my-demo>
<script type="module">
import {Component} from "can";
Component.extend({
tag: "my-demo",
view: `
{{ let value=false }}
{{# if(value) }}
{{ debugger }}
{{/ if }}
<button on:click="value = true">Show</button>
`
});
</script>
The can-view-scope can be used to look up values. scope.log()
prints the scope.
scope.get(key)
reads a key value.
{{debugger(CONDITION)}}
The one argument debugger breaks any time the helper evaluates and the argument evaluates to a truthy value.
<my-demo></my-demo>
<script type="module">
import {Component} from "can";
Component.extend({
tag: "my-demo",
view: `
{{ let value=false }}
{{ debugger(value) }}
<button on:click="value = true">Set to true</button>
`
});
</script>
Parameters
- CONDITION
{KeyLookup Expression|Call Expression}
:an EXPRESSION that if evaluates to a truthy value triggers the debugger.
{{debugger(LEFT, RIGHT)}}
The two argument debugger breaks any time the helper evaluates and the two evaluated arguments are equal to each other.
<my-demo></my-demo>
<script type="module">
import {Component} from "can";
Component.extend({
tag: "my-demo",
view: `
{{ let value=false }}
{{ debugger(value, 2) }}
<button on:click="value = 2">Set to 2</button>
`
});
</script>
Parameters
- LEFT
{KeyLookup Expression|Call Expression}
:an EXPRESSION which compares with RIGHT which if equal triggers the debugger.
- RIGHT
{KeyLookup Expression|Call Expression}
:an EXPRESSION which compares with LEFT which if equal triggers the debugger.
Use
The debugger
helper breaks at its place in the template.
During a break, in the paused inspector there is a special get(<path>)
function to help inspect the current scope. For example, get("book.title")
will attempt to locate book
in the current scope and return its title
property.
Use the helper in development and debugging.
In production, the debugger
never breaks and instead prints a warning.
See also
- Debugging Guide
- Debugging Tutorial