在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)
每个原型显然都包含多个功能.
这样的事情会被认为是好的做法吗?
在浏览器中我得到:请求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)确实有效.
我当然试过重启开发服务器.这可能有什么问题?