简体   繁体   English

在 NodeJS 中,“十进制”也可以用作“十进制”

[英]In NodeJS, 'Decimal' works also as 'decimal'

I am installing and using package decimal.js in NodeJS.我在decimal.js中安装和使用包decimal.js

This package is described here .此处描述此包。

All the examples state that I should be using Decimal .所有示例都说明我应该使用Decimal For some reason, it also works when using decimal .出于某种原因,它在使用decimal时也有效。

What is the rationale behind this?这背后的原理是什么?

I've found a similar question on C# here , which states exactly what I sort of speculated:我在 C# here上发现了一个类似的问题,它准确地说明了我的推测:

The symbol decimal is declared as an alias for Decimal .符号decimal被声明为Decimal的别名。

Is it the same in NodeJS, and how exactly do you go about aliasing something in JavaScript?它在 NodeJS 中是否相同,以及您如何在 JavaScript 中为某些东西设置别名?

For the record, I am importing the package as follows:为了记录,我按如下方式导入包:

import Decimal from 'decimal.js';

And as already implied, this seems to work just as well:正如已经暗示的那样,这似乎也能正常工作:

import decimal from 'decimal.js';

There are two different types of export.有两种不同类型的导出。 Named exports and Default exports.You can read more about it here .命名导出和默认导出。您可以在此处阅读更多相关信息。

From that Page: Named exports are useful to export several values.从该页面:命名导出对于导出多个值很有用。 During the import, it is mandatory to use the same name of the corresponding object.在导入过程中,必须使用相应对象的相同名称。 But a default export can be imported with any name.但是可以使用任何名称导入默认导出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM