Javascript Modular Resources

The proposal

  1. Customize which language features to use, this allows for better runtime speed
  2. There are some proposals about modularizing some resources in Javascript
  3. Bringing Java Developers Together with Javascript
  4. Java is a language that is highly modular, in fact, every language has built-in modules that can be called. So... I would like Javascript to be highly modular like Java and I would be able to select which resources I will use in each part of the code exclusively, explicitly

case 1: Java "modules resources"

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class HelloWorld {

  public static void main(final String[] args) {
    final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("h:mm:ss a 'on' MMMM d, yyyy'.'");
    final LocalDateTime now = LocalDateTime.now();

    System.out.println("Hello, World! The current time is " + dtf.format(now));
  }
}

case 2.1: my idea - Javascript with modules resources

import {
  function,
  constants, 
  RegExp, 
 console
} from ecmascript;

function username(parameter){  
   return parameter
}

const name = "name"; 
let re = new RegExp("ab+c");

console.log(re);
console.log(name);
console.log(username('willow'));

case 2.2: my idea - Javascript with modules resources

'use function, constants, RegExp, console'

function username(parameter){  
   return parameter
}

const name = "name"; 
let re = new RegExp("ab+c");

console.log(re);
console.log(name);
console.log(username('willow'));

case 2.3: my idea - Javascript with modules resources

"use system" // use strict: function, constants, RegExp, console

function username(parameter){  
   return parameter
}

const name = "name"; 
let re = new RegExp("ab+c");

console.log(re);
console.log(name);
console.log(username('willow'));

Notes

  1. "I will use only the function and a constants, regex, console..." so, the rest is ignored
  2. This idea is similar to a Java idea ... So ... I can use few language resources

references - " 1. There are some proposals about modularizing some resources in Javascript":

bibliographic references

@theScottyJam My last idea...

I notice that you've already references this proposal, which attempts to provide an importable standard library to JavaScript. If this proposal were to come through, would it satisfy what you're wanting here, or is there something more?

I'll also note that I've heard around (can't remember where) that some engines will do certain optimizations, and won't load properties on globalThis until you try to access them. In these types of engines, having a globalThis full of different properties shouldn't be a performance concern.

1 Like

If this proposal were to come through, would it satisfy what you're wanting here, or is there something more?

  • Yeah =)
1 Like