【问题标题】:Javascript equivalent to python __init__.pyJavascript 等价于 python __init__.py
【发布时间】:2017-10-04 09:10:29
【问题描述】:

在 python 中,为了在包中公开顶级功能,可以创建一个__init__.py

#__init__.py
from .implmentation import impl_function

def exposed_fn():

  """call impl_function

这会将exposed_fn 公开为导入目录(包)时要使用的主要功能。 javascript 的require 中的这个等价物是什么?

显然您可以执行以下操作。

//init.js?
var impl_function = require('./implmentation.js').impl_function;

var exposed_fn = function () {//call impl_function ...};

//Will expose `exposed_fn` when requiring this file.
module.exports = {
  exposed_fn: exposed_fn
}

//How to expose `expose_fn` when requiring a this folder?????

有没有等价物?到目前为止,所有搜索都没有得到证明。

【问题讨论】:

    标签: javascript package


    【解决方案1】:

    以同样的方式使用index.js 文件似乎可行。如果您从 index.js 文件中导出对象,则可以在文件夹级别访问它们。

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 1970-01-01
      • 2010-12-15
      • 2012-11-18
      • 1970-01-01
      • 2011-08-07
      • 2023-04-11
      • 2013-07-20
      • 1970-01-01
      相关资源
      最近更新 更多