JavaScript has evolved much, and with ES6 (ECMAScript6), JavaScript comes with threading, and classes too.
Example class in ES6 (the file name must be .mjs):
class some_class {
Some_Property = null;
some_function(Some_Param){
}
static some_static_function(Some_Param){
}
async some_function2(Some_Param){
}
static async some_static_function2(Some_Param){
}
}
//Static block for static properties
{
some_class.Some_Static_Prop = null;
}
//ES6 export
export default some_class;
//EOF
Import class to use:
//Static import
import some_class from "./some_class.mjs";
//Dynamic import
(async function(){
var some_class = await import("./some_class.mjs").default;
})();
Run Node.js with ES6 and multi-threading:
node --experimental-modules --experimental-worker \
app.js
Add the 'require' function to ES6:
npm install mjs-require --save
node --experimental-modules --experimental-worker -r mjs-require \
app.js
Run Node.js ES6 with heredoc in Bash:
node --experimental-modules --experimental-worker \
--input-type module <<'HEREDOC'
console.log(Date.now());
HEREDOC
No comments:
Post a Comment