makeActiveBinding seems call the binding function more once when accessing the object, why?

  Kiến thức lập trình

I try to better understand makeActiveBinding. Given the sample code below …

counter <- 0

makeActiveBinding("inc", () {
  counter <<- counter + 1
}, .GlobalEnv)

… I noticed the following:

  1. The binding function is already called once when creating the binding
  2. The binding function seems to be called more than once when accessing inc
  3. The function is also called when accessing the counter variable?

My expectation was:

  1. accessing counter will NOT cause an increment
  2. accesing inc increments the counter by 1

Can someone elaborate on what is going on and why?

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT