pd4d10 / console-importer

Easily import JS and CSS resources from Chrome console.
https://chrome.google.com/webstore/detail/console-importer/hgajpakhafplebkdljleajgbpdmplhie
MIT License
848 stars 57 forks source link

Don't pollute the global namespace #4

Closed OriR closed 2 years ago

OriR commented 5 years ago

Right now when using $i it puts the result (when finished) on the global namespace - the window.

I'm proposing that instead it returns a promise (due to the async nature of import) that evaluates with the result of executing the desired imported module.

Something like this

$i('lodash').then(_ => _.toNumber(null));

This could also be used with top-level await like this

const _ = await $i('lodash');
_.toNumber(null);

This is gives you the control whether or not you want to pollute the global namespace and how. Plus, now you don't have to know how the internal module exposes itself ($, _, etc.)

pd4d10 commented 2 years ago

Duplicate of #14