Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. var N = 100,
  2. i;
  3.  
  4. var FirstWay = function() {
  5. this.doSomeCalculations = function() {
  6. // some calculations here
  7. };
  8.  
  9. window.addEventListener( 'scroll', this.doSomeCalculations );
  10. };
  11.  
  12. for ( i = 0; i < N; i++ ) {
  13. new FirstWay();
  14. }
  15.  
  16. var N = 100,
  17. i,
  18. instances = [];
  19.  
  20. var SecondWay = function() {
  21. this.doSomeCalculations = function() {
  22. // some calculations here
  23. };
  24. };
  25.  
  26. var doCommonCalculations = function() {
  27. var i;
  28.  
  29. for ( i = 0; i < N; i++ ) {
  30. instances[ i ].doSomeCalculations();
  31. }
  32. };
  33.  
  34. for ( i = 0; i < N; i++ ) {
  35. instances.push( new SecondWay() );
  36. }
  37.  
  38. window.addEventListener( 'scroll', doCommonCalculations );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement