I'm building a progressive web app using the Workbox library. There's an example on the Workbox doc which shows that the import statements can be omitted by using a constant.
Code with import statements:
import {registerRoute} from 'workbox-routing';
import {CacheFirst} from 'workbox-strategies';
import {CacheableResponse} from 'workbox-cacheable-response';
registerRoute(
({request}) => request.destination === 'image',
new CacheFirst()
);
Code without import statements:
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js');
const {registerRoute} = workbox.routing;
const {CacheFirst} = workbox.strategies; // same as const CacheFirst = workbox.strategies.CacheFirst
const {CacheableResponse} = workbox.cacheableResponse;
registerRoute(
({request}) => request.destination === 'image',
new CacheFirst()
);
How is it possible to instantiate a CacheFirst object (new CacheFirst()) by using a constant instead of an import? Is this a ES6 feature or something Workbox specific? Couldn't find an answer on Google or SO. How does the CacheFirst object relate to the constant?
As I'm coming from PHP this construct is new to me.