小编End*_*ion的帖子

构建node.js中所需库的最佳实践

我有几个包含辅助函数的实用程序库,我想加载它们,以便可以从控制器中使用它们,我想知道在节点中编写实用程序库的最佳实践是什么.

我有点困惑,因为有几种方法可以做到这一点,我不确定什么是最好/更合适/更可靠.这里有两个选项,但我想知道它们是否是最好的(例如我见过使用的片段module.exports = exports = function(){}等)

//option1.js


"use strict";

module.exports =  function(){

     exports.test1 =  function(){ console.log('hi I'm test1')};
     exports.test2 =  function(){ console.log('hi I'm test2')};
     return exports;
};
Run Code Online (Sandbox Code Playgroud)

//option2.js

"use strict";

module.exports =  {

     test1 : function(){ console.log('soy test1')},
     test2 :  function(){ console.log('soy test2')}

};
Run Code Online (Sandbox Code Playgroud)

//test_controller.js

/* Requiring helpers in different ways */
var option1 = require('./option1.js')();
var option2 = require('./option2.js');
Run Code Online (Sandbox Code Playgroud)

design-patterns require node.js

21
推荐指数
1
解决办法
9395
查看次数

暂停app时Phonegap cordova 2.7.0错误

我使用phonegap工具"create"(创建project_folder package_name project_name)创建了一个干净的cordova 2.7.0项目,并且我已将应用程序部署到我的Nexus 4(androind 4.2.2).没有编写代码.

该应用程序已执行,没有任何错误,因为它已显示phonegap徽标和"apache cordova设备准备就绪".问题是当我点击标准的android右键(显示最近运行的应用程序)时,我在日食LogCat中看到错误发生了:

05-07 18:29:54.957: D/webviewglue(24649): nativeDestroy view: 0x731f4738
05-07 18:30:10.163: D/DroidGap(24649): Paused the application!
05-07 18:30:10.163: D/CordovaWebView(24649): Handle the pause
05-07 18:30:10.453: W/IInputConnectionWrapper(24649): showStatusIcon on inactive InputConnection
05-07 18:30:10.743: D/DroidGap(24649): onDestroy()
05-07 18:30:10.743: D/CordovaWebView(24649): >>> loadUrl(javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};)
05-07 18:30:10.743: D/PluginManager(24649): init()
05-07 18:30:10.753: D/CordovaWebView(24649): >>> loadUrlNow()
05-07 18:30:30.765: E/CordovaWebView(24649): CordovaWebView: TIMEOUT ERROR!
05-07 18:30:30.765: D/Cordova(24649): CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from …
Run Code Online (Sandbox Code Playgroud)

timeout cordova

10
推荐指数
1
解决办法
7565
查看次数

猫鼬:嵌套的ref模型人口

如何填充嵌套引用的模型?

例如:

// 'Collection' model
var CollectionSchema = new Schema({
  collection_name: String,
  _groups: [{ type: Schema.Types.ObjectId, ref: 'Group' }],
});

// 'Group' model
var GroupSchema = new Schema({
  group_name: String,
  _item: { type: Schema.Types.ObjectId, ref: 'Item' }  // To be populated
  _meta: [ { type: Schema.Types.ObjectId, ref: 'Meta' } // To be populated
});

// 'Item' model
var ItemSchema = new Schema({
  item_name: String,
  item_description: String
});

// 'Meta' model
var MetaSchema = new Schema({
  meta_name: String,
  meta_value: String
}); …
Run Code Online (Sandbox Code Playgroud)

mongoose node.js data-structures

0
推荐指数
1
解决办法
3446
查看次数