set
Command set <expression> to <expression>
set <object literal> on <expression>
The set
command allows you to set a value of a variable, property or the DOM. It is similar to the put
command
but reads more naturally for operations like setting variables.
It can also be used to set many properties at once using the set {...} on
form.
When setting a symbol, such as x
, the following rules are used:
x
exists in the current local scope, set the locally scoped valuex
exists in the current element-local scope, set the element-local scoped valuex
with the valueNote that if you wish to set a global variable you must explicitly use the global
modifier unless the symbol starts
with a $
:
set global globalVar to 10
<div _="on click set x to 'foo' then log x">
Click Me!
</div>
<div _="on click set my.style.color to 'red'">
Click Me!
</div>
<button _="on click set { disabled: true, innerText: "Don't click me!" } on me">
Click Me!
</button>