如何从节点模块的函数开头删除包名称

How to remove package name from start of function from a node module

所以我有一个节点模块,但我想知道如何将 something.somethingElse() 变成 somethingElse()

如果函数不使用this:

const somethingElse = something.somethingElse;
or 
const { somethingElse } = require('something');
or 
import { somethingElse } from 'something';

如果确实需要 this,您将需要使用 bind,因此 this 设置正确:

const somethingElse = something.somethingElse.bind(something);

有趣的是,您可能不知道它是否需要 this,除非您尝试它并抛出错误!