x-posted from stack overflow

From: CHYRON (DSMITHHFX)31 Oct 2018 12:21
To: Peter (BOUGHTONP) 7 of 12
Quote: 
var cacheArray = Object.values(alldatesobj).map
	(function(item){
		return item.replace(/100315/,'$&/thumbs';
	});
Yeah that works! (bounce)

I had read about the map function, but according to some folks somewhere on the internet, it should not be needed and costs more cpu cycles (or something).
 
Quote: 
What does alldates.txt contain?

It's an array with key-value pairs, keys are 4-digit dates (mmdd), values are image names (*.jpg) used to display a specific new image each day here:
http://designartcraft.com/photo/afbp.htm and randomly here:
http://designartcraft.com/photo/random.html


The purpose of all this is to cache thumbs (same names, in "/thumbs") for offline.

I'm slowly trying to get up to speed on modren javascript syntax without relying on jquery (which doesn't work in service workers). Long ways to go, obviously.

Thanks!

 
EDITED: 31 Oct 2018 12:32 by DSMITHHFX
From: Peter (BOUGHTONP)31 Oct 2018 23:34
To: CHYRON (DSMITHHFX) 8 of 12
> it should not be needed and costs more cpu cycles (or something).

The same can be said for anything that isn't assembly language.

There's no situation where map is necessary - it can always be replaced with a loop - but there's plenty of situations when it makes code easier to understand and work with, and that should generally be the primary concern for the first iteration of any code. (Which isn't to say always use map - it's possible to misuse just like any construct - but don't be afraid to use it when suitable.)

Performance matters when you can show the difference - if a web script takes half a second to run, then absolutely spend some time to identify and optimise the slowest aspect (and that's not always the most obvious one), but if its 38ms vs 35ms then it's less likely to matter.


> I'm slowly trying to get up to speed on modren javascript syntax without relying on jquery

I recently decided to write a jquery-free library for scattering images, and it's interesting to see what's now possible and how browser vendors have still managed to over-complicate simple tasks.

I found MDN to be the best resource, although sometimes you need to know what to look for first - definitely useful for getting the right polyfills if you want to support older browsers whilst still using modern methods.

From: CHYRON (DSMITHHFX) 1 Nov 2018 09:18
To: Peter (BOUGHTONP) 9 of 12
I'm using MDN quite a lot. Explanations are sparse, useful examples rare, and there's an assumption of underlying familiarity with syntax that can make it pretty difficult to follow.
From: Chris (CHRISSS) 1 Nov 2018 20:15
To: Peter (BOUGHTONP) 10 of 12
What is polyfill?
From: Peter (BOUGHTONP) 1 Nov 2018 21:39
To: Chris (CHRISSS) 11 of 12
It's the thick paste you use on walls to smooth over cracks.

PolyfillaMPinterior.jpg

It's also when you re-implement native functionality from newer browsers in JavaScript for the benefit of older browsers - see for example the Array.prototype.map polyfill.

EDITED: 1 Nov 2018 22:00 by BOUGHTONP
From: Peter (BOUGHTONP) 1 Nov 2018 21:59
To: CHYRON (DSMITHHFX) 12 of 12
> Explanations are sparse

I prefer the term concise - no need to dredge through unnecessary waffle to figure out what something does.


> useful examples rare

Possibly. On most sites I tend towards going straight to the examples because the explanations are waffle, but don't need to with MDN.


> there's an assumption of underlying familiarity

That'll be because it's mostly a reference.

There is a JavaScript Guide which appears very comprehensive, but looking at a few pages it does a horrific job of explaining stuff and has some terrible examples, so, yeah... that sucks. :/

EDITED: 1 Nov 2018 22:01 by BOUGHTONP