Scope chain rules
Scopes cascade up the DOM tree. VSN resolves values and assignments using a predictable order.
Lookup order
1) local scope
2) parent scope
3) root scope
Assignment rules
- If a variable exists up the chain, assignments update the nearest scope that has it.
- If it doesn’t exist, the variable is created locally.
- Use
self.to force a local variable. - Use
parent.orroot.to be explicit.
Example
behavior .list {
count: 0;
behavior .item {
on click() { count += 1; }
on dblclick() { self.count = 100; }
}
}
Single clicks update the list count. Double clicks create a local count on the item.