0

Here is a source viewer for fadeIn() but it does not link out to custom() for some reason.

Also, as a second question, how does one conceptualize all this code...there are so many function calls that I can't even guess as to how much code actually runs when you call .fadeIn() or .fadeOut().

For example:

fadeIn() calls animate() which calls speed() which calls extend()...

As a third question: is this object oriented programming ?

Thanks.

3 Answers3

1

It doesn't use setTimeout(), it uses setInterval(), which is in custom(), which is called at the bottom of the animate() method.

Here's a good tutorial: http://www.schillmania.com/content/projects/javascript-animation-1/

As explained in the tutorial, setTimeout() schedules an event to occur a certain amount of time after the setTimeout() function is called. The problem it's going to take time for the scheduled function to run, and thus the next timeout is going to be scheduled after the first timeout's delay AND the time it took to execute the code.

If you want:

100ms : function x called 
200ms : function x called 
300ms : function x called 
400ms : function x called

and you do:

function x(){
    setTimeout( x , 100);
}
setTimeout( x , 100);

What's going to happen is:

100ms : function x called
first calls execution time + 200ms : function x called
second calls execution time + first calls execution time + 300ms : function x called
third calls execution time + second calls execution time + first calls execution time + 400ms : function x called

So you do:

function x(){

}
setInterval( x , 100);
mowwwalker
  • 16,634
  • 25
  • 104
  • 157
1

Make no mistake, this object oriented programming. Functional programming is completely different (usually looks very different too, search for python or haskell). I think you meant "imperative programming" (like C), which isn't functional programming but doesn't have objects either.

jQuery also supports inheritance which is similar to JavaScripts native prototypical inheritance.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
0

setInterval is often a bad option to use . This is because once an interval is set up it will attempt to execute it every N milliseconds regardless of how existing threads are going - so if your browser is choking on some heavy problem already then setInterval is going to add to that. You have to think long and hard about using setInterval especially with older, less thread-aware browsers. more information here: https://stackoverflow.com/a/5479821/1238884

setTimeout is often better since you only queue the next timeout when your process is done - something like this is sometimes better:

function foo(params) {
  // do stuff here that might block or take time
  setTimeout(function() {
      foo(params);
  }, 1234);
}
Community
  • 1
  • 1
frumbert
  • 2,323
  • 5
  • 30
  • 61