让我向您展示我想要完成的示例:
假设我想调用函数子函数的子函数的子函数(以此类推,假设有50多个子函数),例如:
foo(arg).bar(other).foobar(int, str).execute(str)
Run Code Online (Sandbox Code Playgroud)
并想象有50个以上的子函数,因此键入每个子调用是非常不切实际的。
SO:如何编写一个函数来调用子函数等的子函数(基于数组长度)?,基于这样的数组(例如):
[["foo",["asdf"]],["bar",["other"]],["foobar",[123,"hi"]],["execute",["today"]]]
Run Code Online (Sandbox Code Playgroud)
需要明确的是,我不是简单地尝试使用相应的参数分别调用数组中的每个函数,我可以轻松地做到这一点:
arr.forEach(x=>functionDictionary(x[0])(...x[1])
Run Code Online (Sandbox Code Playgroud)
我只想得到这个:
foo(arg).bar(other).foobar(int, str).execute(str)
Run Code Online (Sandbox Code Playgroud)
由此:
[["foo",["asdf"]],["bar",["other"]],["foobar",[123,"hi"]],["execute",["today"]]]
Run Code Online (Sandbox Code Playgroud) 我想获得所有CSS声明的所有背景和颜色属性值.
例如:
body {
background: #fff;
}
.aaa {
background: #dedede;
color: #000
}
.text {
color: #333;
padding: 10px
}
Run Code Online (Sandbox Code Playgroud)
我想获得这样的输出,并且这些属性的值需要存储在数组中.
body {
background: #fff;
}
.aaa {
background: #dedede;
color: #000
}
.text {
color: #333;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用jQuery来做到这一点.我可以得到一个特定类的背景属性值,如.aaa或.text.我如何获得所有类的值?
$('#btn-invert').on('click', function() {
var color = $("body").css("background");
// var test = invertColor("#00a3fe");
console.log(color);
});
Run Code Online (Sandbox Code Playgroud) 按照这个主题,我尝试生成一个3D弯曲三角形作为NURBS曲面,但是我不知道如何设置3D点来实现。
这是当前的实现:
var edges = this.getEdges(), // An edge is a line following 4 dots as a bezier curve.
dots = self.getDotsFromEdges(edges), // Get all dots in order for building the surface.
ctrlPoints = [ // Is generated only once before, but copy-pasted here for this sample code.
[
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1)
],
[
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, …Run Code Online (Sandbox Code Playgroud) 在 Node.js(正在使用 MS Bot Framework)中,我尝试迭代包含 . 返回的多个对象的数组fetch()。它执行一次迭代,然后抛出一个错误。
我确实已经将节点获取从等式中剔除,并使用了对象的静态数组。我也尝试转换为数组。结果还是一样:TypeError: (images || []).forEach is not a function第一次迭代进展顺利。
这是目前的样子(为了可读性缩短了对象值):
\n\n// exact copy of what fetch returns\nlet test = [\n {\n title: 'Power BI Desktop\xe2\x80\x94Interactive Reports | Microsoft Power BI',\n link: 'https://support.office.com/',\n description: 'Create interactive reports with data',\n thumbnail: 'https://powerbi.microsoft.com/'\n }, {\n title: 'What is Power BI administration? - Power BI',\n link: 'https://support.office.com/',\n description: 'Learn about the configuration of Power BI ',\n thumbnail: 'https://learn.microsoft.com/'\n }, {\n …Run Code Online (Sandbox Code Playgroud) 我有一个数组
Result = [{"01": 330,"02": 353,"03": 178,"04": 353,"KID": 10,"PID": 5},
{"01": 320,"02": 112,"03": 328,"04": 123,"KID": 11,"PID": 6},
{"01": 110,"02": 253,"03": 375,"04": 233,"KID": 12,"PID": 7}]
Run Code Online (Sandbox Code Playgroud)
我知道如何对所有键进行加法运算,如下所示:
Result.forEach(item =>{
let sum = Object.keys(item).reduce((acc,value) => acc + item[value],0);
item["total"] = sum;
})
Run Code Online (Sandbox Code Playgroud)
如何找到排除"KID"和"PID"键值的总和?
问题是,如果我控制台登录此字符串:"Lorem "在console.log将输出:Lorem我不能告诉我们,如果在字符串的结尾有空格或没有。
如何强制控制台在引号中显示输出?
我使用https://github.com/AngularClass/angular2-webpack-starter并遇到以下问题:当我在项目目录中并运行时
karma start
Run Code Online (Sandbox Code Playgroud)
然后我得到:
概括:
? 已完成 0 个测试
但是当我运行时:
npm test
Run Code Online (Sandbox Code Playgroud)
我得到:
概括:
? 已完成 0 个测试
npm 错误!测试失败。有关更多详细信息,请参见上文。
如果我运行:
npm run test
Run Code Online (Sandbox Code Playgroud)
我得到:
SUMMARY:
? 0 tests completed
npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/Cellar/node/7.1.0/bin/node" "/usr/local/bin/npm" "run" "test"
npm ERR! node v7.1.0
npm ERR! npm v4.0.2
npm ERR! code ELIFECYCLE
npm ERR! angular2-webpack-starter@5.0.5 test: `karma start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-webpack-starter@5.0.5 test script 'karma start'.
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我正在寻找要在我的 javascript 代码中使用的正则表达式,如果它们存在,它会给我不带参数的 url 的最后一部分- 这是示例 - 带和不带参数:
https://scontent-fra3-1.xx.fbcdn.net/v/t1.0-9/14238253_132683573850463_7287992614234853254_n.jpg
在这两种情况下,我都想得到:
14238253_132683573850463_7287992614234853254_n.jpg
我在 Php Laravel 中编写 API 并使用 swagger (2.0) 注释(lib:darkaonline/l5-swagger使用swagger-php)来生成 swagger.json,但是我有以下问题 - 当我输入时:
/**
*
* Space Schema
*
* @SWG\Get(
* path="/api/v1/client/space/schema",
* @SWG\Response(
* response=200,
* description="OK",
* @SWG\Property(property="result", type="json", example={ "aa": [ "bb", "cc" ] } )
* )
* )
Run Code Online (Sandbox Code Playgroud)
并尝试生成 swagger.json 我得到:
[Syntax Error] Expected PlainValue, got '[' in ...
Run Code Online (Sandbox Code Playgroud)
但是当我不使用方括号时,例如:
@SWG\Property(property="result", type="json", example={ "ee": "ff" })
Run Code Online (Sandbox Code Playgroud)
然后一切都很好。但是我需要使用方括号所以问题是:
[swagger注释中json字符串中(方括号)的转义字符是什么?
我还想补充一点,我的示例 json 非常大且复杂
我是JavaScript的新手,正在尝试了解吊装和范围的概念。
情况1
var name;
function logName(num) {
console.log(name, num);
}
logName(1);
name = "Auro";
logName(2);Run Code Online (Sandbox Code Playgroud)
我在控制台中有以下输出
Auro 1
Auro 2
Run Code Online (Sandbox Code Playgroud)
如果我理解hoisting正确,那么JS引擎会首先提升变量的声明,然后自动为其赋值undefined。仅当遇到赋值(=)运算符时,它才实际为其分配预期值。
如果我的理解是正确的,则在第一次logName调用该函数时,该变量name应该已打印未定义,但它正在打印该值。
情况二
Auro 1
Auro 2
Run Code Online (Sandbox Code Playgroud)
在控制台中输出:
Baner 1
Auro 2
Run Code Online (Sandbox Code Playgroud)
这让我更加困惑。在这里,对函数的第一个调用logName选择了对变量的后一个分配并打印Baner,但是,第二个调用选择了前一个分配,即Auro。
这里发生了什么?我想念什么?
javascript ×8
arrays ×3
function ×2
node.js ×2
3d ×1
angular ×1
annotations ×1
botframework ×1
console.log ×1
css ×1
cubic-bezier ×1
hoisting ×1
jquery ×1
json ×1
karma-runner ×1
npm ×1
nurbs ×1
php ×1
regex ×1
scope ×1
substring ×1
swagger-2.0 ×1
swagger-php ×1
three.js ×1
unit-testing ×1
url ×1
var ×1