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

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; 导出用于使模块的一部分可用于模块外部的脚本。 所以当有人在另一个

What is this Javascript "require"?

I'm trying to get Javascript to read/write to a PostgreSQL database. I found this project on github. I was able to get the following sample code to run in node. var pg = require('pg'); //native libpq bindings = `var pg = require('pg').native` var conString = "tcp://postgres:1234@localhost/postgres"; var client = new pg.Client(conString); client.connect(); //queries are queued and execute

这个Javascript“需要”是什么?

我试图让Javascript读/写PostgreSQL数据库。 我在github上找到了这个项目。 我能够得到以下示例代码在节点中运行。 var pg = require('pg'); //native libpq bindings = `var pg = require('pg').native` var conString = "tcp://postgres:1234@localhost/postgres"; var client = new pg.Client(conString); client.connect(); //queries are queued and executed one after another once the connection becomes available

Exports property in node?

This question already has an answer here: What is the purpose of Node.js module.exports and how do you use it? 10 answers Exports are the publicly visible interface of a module. When using a module you can access anything that was exported from the module. This allows you to hide private implementation details of your module and only export the objects, properties and functions you want t

在节点中导出属性?

这个问题在这里已经有了答案: Node.js module.exports的用途是什么?你如何使用它? 10个答案 出口是模块公开可见的界面。 使用模块时,您可以访问从模块导出的任何内容。 这允许您隐藏模块的私有实现细节,并只导出想要从外部使用的对象,属性和函数。 模块是隐私和类缺乏Javascript问题的解决方案之一。 使您能够有效地封装私人数据和行为。

javascript objects confusion

Possible Duplicate: What is the purpose of NodeJS module.exports and how do you use it? I have the following code: var express = require('express'); var app = module.exports= express(); require('./config/environment.js')(app, express, __dirname); require('./routes/default.js')(app, __dirname); module.exports = function (app, express, dirname) { .... }; module.exports = function (app, dirn

JavaScript对象混淆

可能重复: NodeJS module.exports的用途是什么?你如何使用它? 我有以下代码: var express = require('express'); var app = module.exports= express(); require('./config/environment.js')(app, express, __dirname); require('./routes/default.js')(app, __dirname); module.exports = function (app, express, dirname) { .... }; module.exports = function (app, dirname) { .... }; 这段代码发生了什么。

node.js export calling another controller method within controller

This question already has an answer here: What is the purpose of Node.js module.exports and how do you use it? 10 answers ConB对象将包含来自该控制器的输出,因此您只需将该方法调用为对象ConB.verify(...)

node.js导出调用控制器内的另一个控制器方法

这个问题在这里已经有了答案: Node.js module.exports的用途是什么?你如何使用它? 10个答案 ConB对象将包含来自该控制器的输出,因此您只需将该方法调用为对象ConB.verify(...)

Where does the "exports" define in PhantomJS?

This question already has an answer here: Is 'require(…)' a common javascript pattern or a library function? 3 answers What is the purpose of Node.js module.exports and how do you use it? 10 answers The phantomJS implemented require syntax (same as NodeJS ) if you want to include external library, that library is injected with module object and module.exports is the public objec

“出口”在PhantomJS中定义在哪里?

这个问题在这里已经有了答案: '需要(...)'是一种常见的JavaScript模式还是库函数? 3个答案 Node.js module.exports的用途是什么?你如何使用它? 10个答案 实施phantomJS require语法(如相同NodeJS ) 如果要包含外部库,则该库将注入module对象和module module.exports是require函数返回的公共对象。 //myMoudle.js var _a = 5; //this is private member of the module module.exports= { a : (

access child view inside the main view in CommonJs module

Current situation: i build a module containing with a view containing a button and two views: function moreButtonView(){ var self=Ti.UI.createView({ height:350, top:-322, width:Ti.UI.FILL }); var info=Ti.UI.createView({ height:322, width:Ti.UI.FILL, top:0, backgroundColor:'#bbbbbb' }); var infoShadow=Ti.UI.createView({ height:322, width:Ti.UI.FILL, top

在CommonJs模块的主视图中访问子视图

目前的情况:我建立一个包含一个包含一个按钮和两个视图的视图的模块: function moreButtonView(){ var self=Ti.UI.createView({ height:350, top:-322, width:Ti.UI.FILL }); var info=Ti.UI.createView({ height:322, width:Ti.UI.FILL, top:0, backgroundColor:'#bbbbbb' }); var infoShadow=Ti.UI.createView({ height:322, width:Ti.UI.FILL, top:3, backgroundColor:'#0

Problems managing CommonJS modules

I am using Titanium Appcelerator to develop apps using JavaScript. They have suggested to use the CommonJS approach. A brief example on CommonJS can be found here. For the life of me, I cannot still figure out how to structure my code. Example: /* Homescreen.js */ exports.createHomescreen = function () { //load all required modules first var videoPlayer = require('ui/videoPlayerMo

管理CommonJS模块的问题

我正在使用Titanium Appcelerator来使用JavaScript开发应用程序。 他们建议使用CommonJS方法。 关于CommonJS的简单例子可以在这里找到。 对于我的生活,我仍然无法弄清楚如何构建我的代码。 例: /* Homescreen.js */ exports.createHomescreen = function () { //load all required modules first var videoPlayer = require('ui/videoPlayerModule'); var self = Ti.UI.createWindow({ width:'100

CommonJS for OOP in Appcelerator Titanium

Is it good practice to write all javascript "classes" as CommonJS modules within an Appcelerator Titanium Mobile app instead of using functions / object notation to create a new "class" (or how you call them in javascript anyway)? var module = require('lib/module'); instead of var object = new MyClass(); Are there any disadvantages? I do not believe it is completely supp

CommonceS适用于Appcelerator Titanium中的OOP

在Appcelerator Titanium Mobile应用程序中将所有JavaScript“类”作为CommonJS模块编写,而不是使用函数/对象表示法来创建新的“类”(或者您如何在JavaScript中调用它们),是否是一种很好的做法? var module = require('lib/module'); 代替 var object = new MyClass(); 有什么缺点吗? 我不相信目前在所有平台和SDK的所有版本上都完全支持它。 在QA论坛中查看此问题 http://developer.appcelerator.com/question/1253

use of module.exports as a constructor

According to the Node.js manual: If you want the root of your module's export to be a function (such as a constructor) or if you want to export a complete object in one assignment instead of building it one property at a time, assign it to module.exports instead of exports. The example given is: // file: square.js module.exports = function(width) { return { area: function() {

使用module.exports作为构造函数

根据Node.js手册: 如果您希望模块导出的根是一个函数(如构造函数),或者如果要在一个赋值中导出完整对象而不是一次构建一个属性,请将其分配给module.exports而不是导出。 给出的例子是: // file: square.js module.exports = function(width) { return { area: function() { return width * width; } }; } 并像这样使用: var square = require('./square.js'); var mySquare = square(2); console