I try to better understand makeActiveBinding
. Given the sample code below …
counter <- 0
makeActiveBinding("inc", () {
counter <<- counter + 1
}, .GlobalEnv)
… I noticed the following:
- The binding function is already called once when creating the binding
- The binding function seems to be called more than once when accessing
inc
- The function is also called when accessing the
counter
variable?
My expectation was:
- accessing
counter
will NOT cause an increment - accesing
inc
increments the counter by 1
Can someone elaborate on what is going on and why?
2