module - Static import in JavaScript -
module - Static import in JavaScript -
if have module public fellow member , utilize this
module.sub.member()
then best (if exists) way static import fellow member local scope, using
in cpp or import static
in java?
var app = (function(app) { /* dependencies */ var sound = app.modules.sound, input = app.modules.io.input, ... /* actual code using dependecies */ ... })(app || {});
this solution has several advantages:
stated @ top of module, it's visible @ first glimpse (maintainable code) ,
usual benefits of imports: less typing, avoidance of namespace clashes etc. (maintainable code)
long property path look-ups (a.b.c.d
) needed 1 time (performance) ,
using local variable faster, using global variable - quicker look-ups (performance),
minification tools can minify local variable names safely, can't trivially minify global variables.
javascript module
Comments
Post a Comment