Is there an equivalent to didSet
from Swift
in Javascript
? Basicall to call a function automatically when a variable is altered. The purpose of this would be instead of having to call a function each time as follows:
var x = someType()
x.behavior = newBehavior
alterBehavior(x, newBehavior)
function alterBehavior(var,behavior) { // change behavior of var }
I could just do
var x = someType()
someType didSet { // change behavior of var }
x.behavior = newBehavior
This is a trivial example but for my use case this would save me a ton of time / function calls for each sub property everytime it's changed.