What is exports and prototype in Javascript?

后端 未结 2 1515
长发绾君心
长发绾君心 2020-12-23 01:59

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?

//f         


        
相关标签:
2条回答
  • 2020-12-23 02:31

    This video explains node.js module.exports and here is a resource which describes JavaScript prototype.

    0 讨论(0)
  • 2020-12-23 02:42

    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.

    0 讨论(0)
提交回复
热议问题