1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
---
layout: default
permalink: docs/introspection.html
---
# Introspection API
Stylus supports an introspection API. This allows mixins and functions to reflect relative to the caller, etc.
## mixin
The `mixin` local variable is automatically assigned within function bodies.
It contains the string `root` if the function was called at the root
level, or `block` indicating otherwise, and finally `false` if the invoked function expects a return value.
In the following example, we define `reset()` to alter its behaviour depending on whether it's mixed into root, into another block, or into a return value, as used in the `foo` property below:
reset()
if mixin == 'root'
got
root true
else if mixin
got 'a mixin'
else
'not a mixin'
reset()
body
reset()
foo reset()
Compiles to:
got {
root: true;
}
body {
foo: "not a mixin";
got: "a mixin";
}
|