Js on-stack and off-stack

clipboard.png
modifying scrollTop is not valid because it is a shallow copy. It specifies a value that has nothing to do with the original object. How to write it?

Feb.28,2021

 function scroll() {
            return {
                top: window.pageYOffset || document.documentElement.scrollTop,
                left: window.pageXOffset || document.documentElement.scrollLeft
            }
        }

scroll (). Top


var scrollTop =. write in the timer


both have getter and setter. You take the value out of the value. Setter is to modify the actual content. Your changes to your variables have nothing to do with the original setter.


const realScroll = [
  [document.body, 'scrollTop'],
  [window, 'pageYOffset'],
  [document.documentElement, 'scrollTop']
];
const len = realScroll.length;
let time = setInterval(function() {
  let i = 0,
      getter = function() {
        return realScroll[i][0][realScroll[i][1]];
      },
      setter = function(v) {
        realScroll[i][0][realScroll[i][1]] = v;
      },
      top;
  for (; i < len; iPP) {
    top = getter();
    if (top) {
      setter(top - 200);
      if (top <= 0) {
        clearInterval(time);
      }
    }
  }
});
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b366d0-e561.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b366d0-e561.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?