Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 969 Bytes

introspection.md

File metadata and controls

38 lines (27 loc) · 969 Bytes

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";
    }