animation - javascript function with an argument calling without argument -


can tell me, how works example

function animate(t) {        sun.rotation.y = t/1000;     renderer.clear();     camera.lookat(sun.position);     renderer.render(scene, camera);             window.requestanimationframe(animate, renderer.domelement); }; animate(new date().gettime()); 

as see, animate() function has argument "t". , call function it. inside animate() func requestanimationframe called without "t" , program works perfect..im confused

general case

javascript not require pass arguments in function. if don't pass argument, variable default undefined.

you can pass more arguments specified function, , access them arguments object, array-like object holds arguments passed function. in example t shorthand arguments[0]. can have following.

function sumtwonumbers(){  return arguments[0] + arguments[1] }  sumtwonumbers(2,3) //returns 5 

or this

function gettwo(a,b,c,d) {    return 2; }  gettwo(); //returns 2 no errors 

your case

but inside animate() func requestanimationframe calls without "t"

it should noted function isn't being called without argument there. 'animate' being passed argument function (which presumably call function @ point). when function referred without () afterwards, being passed object, not executed. functions objects in js , therefore can passed functions other object. following valid

function a(x){   return x+2; }  function b(y,z){    return y(z); }  b(a,2); //returns 4 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -