首页 >> 要闻 >

exportservice(exports)

2023-10-30 18:50:39 来源: 用户: 

你们好,最近小时发现有诸多的小伙伴们对于exportservice,exports这个问题都颇为感兴趣的,今天小活为大家梳理了下,一起往下看看吧。

1、 首先比如写一个exports_test.js模块,代码如下:

2、 Var name=' I am the name variable that defines the variable declaration;exports.name=' I am the attribute name underexports' Function sayName(){ console.log ('I am the sayName () method of function declaration! '); }exports.sayname1=function () {console.log ('I am a method underexports! '); };

3、 然后创建一个新的test.js,引入上面的模块:

4、 varexports_test=require('./exports_test.js');

5、 控制台。日志(exports _ test);//输出

6、 执行test.js后,可以看到如图所示的输出结果。

7、 从上面可以看出,任何exports的属性和方法都可以从外部访问,而var声明和funciton直接定义的方法是私有的,只有在exports暴露后才共享。

8、 只能通过exports_test.name获取外部,如下所示

9、 console.log(exports_test.name);console.log(exports_test.sayName1());

以上就是exports这篇文章的一些介绍,希望对大家有所帮助。

  免责声明:本文由用户上传,与本网站立场无关。财经信息仅供读者参考,并不构成投资建议。投资者据此操作,风险自担。 如有侵权请联系删除!

 
分享:
最新文章