javascript - Does setInterval() require different function names? -
when learning vue, created 2 timers updating component data. when copy/pasting, did not change, mistake, name of second function in setinterval()
code runs correctly nevertheless (the vue part not relevant, keep have functioning example core of question timers @ bottom of code):
var data_mynumber = { time: 1 }; vue.component('mynumber', { template: '<div>time {{time}}</div>', data: function() { return data_mynumber; } }) var data_smthg = { time: 5 }; vue.component('smthg', { template: '<div>hello {{time}}</div>', data: function() { return data_smthg; } }) var vm = new vue({ el: '#root' }) setinterval( function mytimer() { var d = new date(); data_mynumber.time = d.tolocaletimestring(); }, 1000 ); setinterval( function mytimer() { var d = new date(); data_smthg.time = d; }, 100 );
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.5/vue.js"></script> <div id="root"> <mynumber></mynumber> <smthg></smthg> </div>
both setinterval()
call same function name mytimer()
, each of them being different. code runs expected: timers have different tempo.
is working chance or can reuse same function name across setinterval()
calls?
as matter of fact don't need name of function. it's called anonymous functions or lambdas , doesn't make difference name. passing parameter, callback. won't call name of function, call reference.
in case of code be
setinterval( function() { var d = new date(); data_mynumber.time = d.tolocaletimestring(); }, 1000 );
Comments
Post a Comment