Node currently includes building a class in strict mode.
If I have the following class:
"use strict" class MyClass { constructor(foo) { this.foo = foo } func(){/*ETC */} }
What is the appropriate export operator for exporting it to another module. What about an import statement from another file?
Similarly, you are currently “importing” or “exporting” anything else currently to node using commonJS requireand module.exports:
require
module.exports
Foo.js
class Foo {} module.exports = Foo // or if you want to edit additional objects: // module.exports.Foo = Foo // module.exports.theNumberThree = 3
Bar.js
var Foo = require("./Foo") var foo = new Foo()
, Node ES6. , / ES6 CommonJS.
:
//MyClass.js class MyClass { constructor(foo) { this.foo = foo } func(){/*ETC */} } module.exports = function(foo){ return new MyObject(foo); }
//in app.js var myClass = require('./MyClass'); var mc = new myClass(foo);
Source: https://habr.com/ru/post/1616460/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1616455/pandas-dataframe-expand-rows-with-lists-to-multiple-row-with-desired-indexing-for-all-columns&usg=ALkJrhjWl99l1O2CT9Q__PZb4Zg2iaoyYgUnderstanding QScopedPointer following a link - c ++R how to "divide" into combined subsets? - splitDjango log output to start server in file - pythonUsing `executemany` to update records in an existing SQLite3 database (using Python sqlite3) - pythonHow to convert a very long binary number to decimal? - mathPython Pandas Summary if the description contains a phrase in a list - pythonHow to use conf file name from confin file? - nginxГде поместить REST API-звонки в дядю Боба Чистая архитектура? - androidдинамическое тело в блестящей приборной панели - rAll Articles