ecmascript 6 - Import into object? -
let's start example:
import renewcreeplife '../tasks/renew_creep_life'; import harvestenergy '../tasks/harvest_energy'; import pickupenergy '../tasks/pickup_energy'; import storeenergy '../tasks/store_energy'; import upgradecontroller '../tasks/upgrade_controller'; const taskfuncs = { [tasks.renew]: renewcreeplife, [tasks.pickup_energy]: pickupenergy, [tasks.harvesting]: harvestenergy, [tasks.storing]: storeenergy, [tasks.upgrading]: upgradecontroller, };
is there way simplify i'm not creating these pointless temporary variable names? like:
// incorrect desired syntax const taskfuncs = { [tasks.renew]: import '../tasks/renew_creep_life', };
n.b. each of files using export default function()
no. import
statement not have return value, can never used assign directly variable that.
additionally, import
, export
must declared @ top level.
this not possible es6 , stay way foreseeable future (es2016+).
however, there html module loader spec being worked on allow load modules like:
system.import('../tasks/renew_creep_life') .then(renewcreeplife => { });
but since it's promise-based, you'll still not able write inline in object that.
if want synchronous loading, nodejs' require
closest you'll get. there browser implementations such webpack/browserify/etc. attempt mimic behaviour:
const taskfuncs = { [tasks.renew]: require('../tasks/renew_creep_life').default };
Comments
Post a Comment