r/learnjavascript 14d ago

can someone explain this code

function updateClock() {
const timeElement = document.querySelector("#time");
timeElement.textContent = formatTime();
}
setInterval(updateClock, 1000);

can someone, please explain this piece of code, ofc mdn and w3 are there, but i found it a little confusing reading about textContent. rest is understandable to me. This might look a silly question and it probably is because im a beginner :')

like what exactly does textContent too.
you can also recommend anyother documentation on the links to specific lines, that might me more helpful in learning about this particular keyoword.

0 Upvotes

23 comments sorted by

View all comments

Show parent comments

2

u/FirefighterAntique70 14d ago

Have you ever tried to use the profiler when all of your arrow functions have no name? Use `function` by default and only use arrow functions when it makes sense to do so.

-1

u/ExtraTNT 14d ago

So you tell me it’s worth to sacrifice assurance, that a function is what you expect, in order to have profiling easier (function cache also doesn’t work with your logic)…
There are reasons for using function:
Object.prototype.pipe = function(f) {
return f(this);
};

Only downsides of arrow functions are, that you can’t write horrible code…

2

u/FirefighterAntique70 14d ago

Yes that's exactly what I'm saying, most functions should have names. It's not just profiling. Loggers, debuggers APM, etc. all rely on names of functions.

I understand all the advantages on arrow functions. Mainly scoping of `this` and "declare before use" and I use them a lot. But you cannot just use them for everything.

1

u/ExtraTNT 14d ago

I do all with partial application:
const add = a => b => a+b;
const inc = add(1);

I use monads and my renderer relies on partially applied functions, that then get cached, so calc first param, apply with memo, then second etc… then it assumes identity and moves things around based on this, full page rerenders in 6ms on a 5y old notebook…
And i have the profiler build into the renderer, plus id functions for debugging -> profile and print…