Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. ```javascript
  2. mutateElementToAffectOffsetTop(someElement);
  3.  
  4. // (1) We don't know the value of someElement.offsetTop here because we compute it lazily.
  5.  
  6. var y = (new DOMTransaction(function () {
  7. // (2) We need to remember the "old value" of someElement.offsetTop here.
  8. mutateElementToAffectOffsetTop(someElement);
  9. return someElement.offsetTop;
  10. })).execute();
  11. ```
  12.  
  13. If `DOMTransaction` were to preserve the old value, then `y` needs to be identically equal to the value of `someElement.offsetTop` at (1). However, since nobody had asked for the value in (1), we're forced to pre-compute the value at (2). It's worse than that. `mutateElementToAffectOffsetTop` might be using the old value of other computed CSS values in which case we have to pre-compute all the property values that could be queried by the script at (2).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement