What is exports and prototype in Javascript?

I am new to Javascript and am seeing a lot of usage of exports and prototype in the code that I read. What are they mainly used for and how do they work?

//from express
var Server = exports = module.exports = function HTTPSServer(options, middleware){
  connect.HTTPSServer.call(this, options, []);
  this.init(middleware);
};

Server.prototype.__proto__ = connect.HTTPSServer.prototype;

Exports is used to make parts of your module available to scripts outside the module. So when someone uses require like below in another script:

var sys = require("sys");  

They can access any functions or properties you put in module.exports

The easiest way to understand prototype in your example is that Server is a class that inherits all of the methods of HTTPSServer . prototype is one way to achieve class inheritance in javascript.


这段视频解释了node.js module.exports,这里是一个描述JavaScript原型的资源。

链接地址: http://www.djcxy.com/p/96632.html

上一篇: PyPy:在整数列表中使用None时性能会受到严重影响

下一篇: JavaScript中的输出和原型是什么?