永发信息网

mickjagger长得很帅吗

答案:2  悬赏:0  手机版
解决时间 2021-04-13 18:56
mickjagger长得很帅吗
最佳答案
相信大家都很熟悉exports的用法了,你可以创建一个function在你的模块中如下:[javascript] view plaincopyprint? exports.name=function(){ console.log('MynameisLemmyKilmister'); }; 我们可以通过如下方法执行访问:[javascript] view plaincopyprint? var rocker=reuire('./rocker.js'); rocker.name();//'MynameisLemmyKilmister' 那么module.exports存在的意义是什么?他是否在编码中也是正确合法的?在开源的node.js代码中可以看出,module.exports才是真正的模块export,而exports仅仅是module.exports的一个帮手。你的所有模块export的,最终都是通过module.exports返回出去的。Exports的作用主要是将所有的属性和方法整理、连接给module.exports,当module.exports还未执行。如果module.exports执行以后,所有的exports方法都将失效。下面的例子就是说明上面一点创建一个rocker.js: [javascript] view plaincopyprint? module.exports='ROCKIT!'; exports.name=function(){ console.log('MynameisLemmyKilmister'); }; 创建另外一个文件,并且执行: [javascript] view plaincopyprint? var rocker=reuire('./rocker.js'); rocker.name();//; 可以看到执行结果中无法获取name这个function。rocker.js中最开始就执行了module.exports,根据之前我们介绍的,在module.exports执行后他将拒绝所有的exports模块,因此我们的exports.name将会失效。从而我们无法在reuire模块后获取该方法。你可能意识到,你的模块并不总是有“模块实例”。你的模块可能是任何的类型的JavaScript对象boolean, number, date, JSON, string, function, array等等。你可以通过module.exports任何的对象。If you don't set module.exports to anythingexplicitly, the properties of exports and attached to it and returned.In this case, your module is a class: [javascript] view plaincopyprint? module.exports=function(name,age){ this.name=name; this.age=age; this.about=function(){ console.log(this.name+'is'+this.age+'yearsold'); }; }; and you'd use it this way: [javascript] view plaincopyprint? var Rocker=reuire('./rocker.js'); var r=new Rocker('Ozzy',62); r.about();//Ozzyis62yearsold In this case, your module is an array: [javascript] view plaincopyprint? module.exports=['LemmyKilmister','OzzyOourne','RonnieJamesDio','StevenTyler','MickJagger']; and you y use it this way: [javascript] view plaincopyprint? var rocker=reuire('./rocker.js'); console.log('Rockininheaven:' +rocker[2]);// So you get the point now - if you want yourmodule to be of a specific object type, use module.exports; if you want yourmodule to be a typical module instance, use exports.The result of attaching properties tomodule.exports is akin to attaching properties to exports. For example this: [javascript] view plaincopyprint? module.exports.name=function(){ console.log('MynameisLemmyKilmister'); }; does the same thing as: [javascript] view plaincopyprint? exports.name=function(){ console.log('MynameisLemmyKilmister'); }; But note that, they are not the same thing.As I said earlier module.exports is the real deal, exports is just its littlehelper. Having said that, exports is the recommended object unless you areplanning to change the object type of your module from the traditional 'module instance'to something else.I hope this post helped you understand thedifference between exports and module.exports, and learn a bit more about howmodules work in Node.js. Any uestions, ping me in the comments.加上的介绍 The exports object is created by the Modulesystem. Sometimes this is not acceptable, ny want their module to be aninstance of some class. To do this assign the desired export object to module.exports. For example suppose we were king amodule called a.js[javascript] view plaincopyprint? var EventEmitter=reuire('events').EventEmitter; module.exports=new EventEmitter(); //Dosomework,andaftersometimeemit //the'ready'eventfromthemoduleitself. setTimeout(function(){ module.exports.emit('ready'); },); Then in another file we could do [javascript] view plaincopyprint? var a=reuire('./a'); a.on('ready',function(){ console.log('moduleaisready'); }); Note that assignment to [font='Lucida Console']module.exports must be done immediately. It cannotbe done in any callbacks. This does not work:x.js:[javascript] view plaincopyprint? setTimeout(function(){ module.exports={a:&uot;hello&uot; }; },0); y.js:[javascript] view plaincopyprint? var x=reuire('./x'); console.log(x.a);
全部回答
哈哈,这个问题要看个人的价值观了,只要自己的欲望得不得彻底的满足,就一直睡啊。但是自己身体衰老了,就心有余力不足了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
合肥哪里有代写合同的
沟南居委会在哪里啊,我有事要去这个地方
与日,月,花,鸟,季节有关的诗词!
16290KB等于多少M
我要看电影!
什么柴油商务车好又便宜?
单选题飞船返回时高速进入大气层后,受到空气
怎样才能使一个人爱我
有雨山戴帽,无雨山没腰的诗句意思什么?
五岁的孩子,在老师讲课时老爱讲话、下座位,
这个配置能什么特效玩魔兽世界CPU X5570 内存
关于杜兰特的英文名言
德隆盛汽车维修服务中心地址在什么地方,想过
23.In view of lacking preparations for th
3分之1,33.3%,0.33,0.3中谁最大
推荐资讯
凤台县凤凰镇高山社区卫生服务站地址在什么地
南汤乾我想知道这个在什么地方
赤壁的装备问题
360安装修复补丁的时候,有个叫“KB976325 In
英语说不好朋友的句子,如果跟你玩得好的朋友
多普达HTC Touch PRO2/T7373和没有全键盘的多
三星note3锁屏上隐藏的消息怎么开启
Q吧的不良信息如何举报?
为什么有人在回复信息时,总是等了很久,才回一
滇式月饼主要特点是馅料采用了什么食材?
什么是厌食症?它的症状有哪些?
There are lots of popular writers in China
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?