小编JaH*_*Hei的帖子

编写node.js模块时的好习惯是什么

在node.js中编写模块时,我无法真正掌握被认为是好的和坏的做法.有些模块似乎使用了大量的出口,而其他模块只使用了一个,等等.

例:

var self;
var mymodule = function() {
    self = this;
    this.value1 = something;
    this.value2 = somethingElse;
};
module.exports.init = function() {
    return new mymodule();
};

mymodule.prototype.functionalityType1 = {
    someFunction: function(callback) {
        var a = self.value1;
        anotherfunction(a, callback);
    },
};
mymodule.prototype.functionalityType2 = {
    someFunction: function(callback) {
        var a = self.value2;
        anotherfunction(a, callback);
    },
};

var anotherfunction = function(v, callback) {
   // do stuff with v
   callback(result);
};
Run Code Online (Sandbox Code Playgroud)

每个原型显然都包含多个功能.

这样的事情会被认为是好的做法吗?

node.js

9
推荐指数
1
解决办法
3365
查看次数

Django url虽然它应该不匹配

在浏览器中我得到:请求URL: http:// xxxxxx:8000/person/test /

使用person.urls中定义的URLconf,Django按以下顺序尝试了这些URL模式:
^person/ ^$
^person/ ^person/(?P<slug>[-\w]+)/$
^admin/
当前URL person/test/与其中任何一个都不匹配.

在python shell中我得到:
import re
url = 'person/test/'
pattern = re.compile(r'^person/(?P<slug>[-\w]+)/$'
re.match(pattern,url)
<_sre.SRE_Match object at 0xb7716860>

所以它显然应该匹配正则表达式.仅使用url person /(^ $ regexp)确实有效.

我当然试过重启开发服务器.这可能有什么问题?

python django django-urls

2
推荐指数
1
解决办法
883
查看次数

标签 统计

django ×1

django-urls ×1

node.js ×1

python ×1