programing

Javascript에서 내보내기 및 프로토 타입이란 무엇입니까?

randomtip 2021. 1. 16. 09:32
반응형

Javascript에서 내보내기 및 프로토 타입이란 무엇입니까?


저는 Javascript를 처음 사용하며 읽은 코드에서 내보내기 및 프로토 타입을 많이 사용하고 있습니다. 주로 무엇에 사용되며 어떻게 작동합니까?

//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;

내보내기 는 모듈 외부의 스크립트에서 모듈의 일부를 사용할 수 있도록하는 데 사용됩니다. 따라서 누군가 require다른 스크립트에서 아래와 같이 사용할 때 :

var sys = require("sys");  

사용자가 입력 한 모든 기능 또는 속성에 액세스 할 수 있습니다. module.exports

예제에서 프로토 타입을 이해하는 가장 쉬운 방법 Server은의 모든 메서드를 상속하는 클래스입니다 HTTPSServer. prototype자바 스크립트에서 클래스 상속을 달성하는 한 가지 방법입니다.


비디오는 node.js module.exports에 대해 설명하며 여기 에는 JavaScript 프로토 타입을 설명하는 리소스가 있습니다.

참조 URL : https://stackoverflow.com/questions/5380159/what-is-exports-and-prototype-in-javascript

반응형