- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写我的第一个 NodeJS 模块,但我无法理解一些概念。
这是我目前拥有的代码(genexer 计数器/生成器):
"use strict";
var ret = require('ret');
module.exports = function (regex) {
if (Object.prototype.toString.call(regex) === '[object RegExp]') {
regex = regex.source;
}
else if (typeof regex !== 'string') {
regex = String(regex);
}
try {
var tokens = ret(regex);
}
catch (exception) {
return false;
}
return {
charset: '',
reference: [],
count: function (token) {
var result = 0;
if ((token.type === ret.types.ROOT) || (token.type === ret.types.GROUP)) {
if (token.hasOwnProperty('stack') === true) {
result = 1;
token.stack.forEach(function (node) {
result *= count(node);
});
}
else if (token.hasOwnProperty('options') === true) {
var options = [];
token.options.forEach(function (stack, i) {
options[i] = 1;
stack.forEach(function (node) {
options[i] *= count(node);
});
});
options.forEach(function (option) {
result += option;
});
}
if ((token.type === ret.types.GROUP) && (token.remember === true)) {
reference.push(token);
}
}
else if (token.type === ret.types.POSITION) {
}
else if (token.type === ret.types.SET) {
token.set.forEach(function (node) {
if (token.not === true) {
if ((node.type === ret.types.CHAR) && (node.value === 10)) {
}
}
result += count(node);
});
}
else if (token.type === ret.types.RANGE) {
result = (token.to - token.from + 1);
}
else if (token.type === ret.types.REPETITION) {
if (isFinite(token.max) !== true) {
return Infinity;
}
token.value = count(token.value);
for (var i = token.min; i <= token.max; ++i) {
result += Math.pow(token.value, i);
}
}
else if (token.type === ret.types.REFERENCE) {
if (reference.hasOwnProperty(token.value - 1) === true) {
result = 1;
}
}
else if (token.type === ret.types.CHAR) {
result = 1;
}
return result;
}(tokens),
generate: function () {
return false;
},
};
};
问题:
count
? count: function (token) {}(tokens)
?count
方法?我收到“ReferenceError:计数未定义”请原谅我没有发布 3 个不同的问题,但我还不是很熟悉所有的术语。
最佳答案
count: (function(args) {return function() {}})(args)
但您的方式也适用于所有环境。所以你可以使用像下面的框架这样的声明来定义你的模块
module.exports = function (regex) {
//...
var count = function(tokens) {
//...
return function() {
//...
var ret *= count(node);
return ret;
}
}
var mymod = {
count: count(tokens)
//...
};
//...
return mymod;
};
关于javascript - NodeJS模块开发的疑惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20408044/
我有以下变量: string str1 = "1"; string str2 = "asd"; string str3 = "3.5"; string str4 = "a"; 现在我需要找到每个字符串
这个问题在这里已经有了答案: Is Java "pass-by-reference" or "pass-by-value"? (92 个回答) 关闭 8 年前。 public class progr
我对这种行为有些疑惑。谁能解释一下 void Decrement(int* x){ *x--; //using this line, the output is 5
您好 StackOverflow 用户(或 Stackoverflowers?): 我正在通过编写 WPF 代码来学习。我阅读了几篇文章/看到了几个截屏视频,并且来自 WEB 开发背景,我启动了 VS
在阅读 HTML5 IndexedDB Specification 时我对它的异步请求模型有些怀疑。查看 request api example 时, open 方法用于启动异步请求。 var req
有几个问题,首先是这个方法,它将 int[] 转换为 byte[]: public static byte[] intToByte(int[] input){ ByteBuffer byteB
我是一名优秀的程序员,十分优秀!