我想在我的JavaScript代码中包含几个JSON文件,这些文件与我的JavaScript源文件位于同一目录中.
如果我想要包含另一个JavaScript文件,我可以简单地使用require
.现在我正在使用readFileSync
并__dirname
获得JSON,我认为这是一种丑陋的方式.
是否有类似的要求,使我能够加载JSON文件?
任何人都可以向我解释为什么A
是真的并且B
是假的?我本以为B也是如此.
function MyObject() {
};
MyObject.prototype.test = function () {
console.log("A", this instanceof MyObject);
(function () {
console.log("B", this instanceof MyObject);
}());
}
new MyObject().test();
Run Code Online (Sandbox Code Playgroud) 如何找出尚未推送到另一个存储库的工作.换一种说法; 如果我要删除该存储库,我会永久松散什么?
目前我使用以下3行,但我想知道这是否是一个完整的封面,如果它是一个理智的方法:
git status --short
git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
git stash list
Run Code Online (Sandbox Code Playgroud)
更新:似乎未检查子模块.有没有办法递归包含子模块?
目前我们正在使用SVN.我想开始使用GitHub,但一个绝对要求是我们需要像我们现在一样对代码进行预先(premerge)验证.GitHub是否支持precommithooks(premergehooks)?
我们是一个由5名开发人员组成的团队.我们达成了一个协议,所有代码(JavaScript)都应该通过类似JSLint的验证.事实证明,自愿验证不起作用,因为它很容易被遗忘.我们怎样才能确保其他人可用的代码能够保证对JSLint(或类似的)进行验证?
我试图弄清楚当与闭包结合使用时std :: function引擎盖下发生了什么.我还无法绕过它,例如:正在调用什么构造函数?任何人都可以发布一个简单的drop的工作示例来替换std :: function,它支持以下示例中所需的功能吗?
#include <functional>
int main(int argc, char* argv[])
{
int mybool = 5;
auto foo = [&] (int arg) {
return mybool * arg;
};
std::function<int(int)> foo2 = foo;
int result = foo2(42);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 以下代码在windows下的node.js中生成异常:
var Socket = require("net").Socket;
socket = new Socket();
socket.connect(80, "localhost");
Run Code Online (Sandbox Code Playgroud)
这是消息:
events.js:2083: Uncaught Error: getHostByName ENOTFOUND
Run Code Online (Sandbox Code Playgroud)
当我删除localhost
,它工作正常.可能是什么导致了这个?我尝试关闭防火墙,但没有效果.
我已经阅读了有关多种不同的git分支策略的内容,并且我认为主分支经常被用作"生产就绪"分支,并且会有一个额外的uat和dev分支.我正在考虑使用相同的3个分支来设置我们的git存储库,但是让'master'包含dev代码并添加一个生产和uat分支.这样,开发人员可以简单地合并到默认的git分支(即'master').有没有理由不那样做?
GR,
科恩
在分析nodejs程序时,我发现61%的滴答声是由"未知"引起的(见下文).这可能是什么?我应该寻找什么?
GR,
科恩
Statistical profiling result from node, (14907 ticks, 9132 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
9132 61.3%
[Shared libraries]:
ticks total nonlib name
1067 7.2% 0.0% C:\Windows\SYSTEM32\ntdll.dll
55 0.4% 0.0% C:\Windows\system32\kernel32.dll
[JavaScript]:
ticks total nonlib name
1381 9.3% 10.0% LazyCompile: *RowDataPacket.parse D:\MI\packet.js:9
......
Run Code Online (Sandbox Code Playgroud) 存储库https://github.com/microsoft/vscode-extension-samples/tree/master/lsp-sample中的 lsp-sample显示了如何实现onCompletion
服务器只听字母 [az] 而不是句点 (.) 我已经看到这是用 控制的triggerCharacters
,但我不清楚在哪里设置这些。这似乎需要在客户端部分完成,但似乎我只能注册另一个onCompletion
处理程序。有人可以透露一些信息吗?
这是服务器端代码:
// This handler provides the initial list of the completion items.
connection.onCompletion(
(_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
// The pass parameter contains the position of the text document in
// which code complete got requested. For the example we ignore this
// info and always provide the same completion items.
return [
{
label: 'TypeScript',
kind: CompletionItemKind.Text,
data: 1
},
{
label: 'JavaScript',
kind: CompletionItemKind.Text, …
Run Code Online (Sandbox Code Playgroud) visual-studio-code vscode-extensions language-server-protocol
今天我遇到了一个意想不到的 TypeScript 编译器行为。我想知道这是一个错误还是一个功能。可能它会是最后一个,但我想知道它背后的原理。
如果我声明一个接口方法,其参数可以是 a string | number
,并创建一个实现该接口的类,则该类方法只能使该参数成为string
。这会导致类实现不需要数字,但编译器允许传递该数字的情况。为什么这是允许的?
interface Foo {
hello(value: string | number): void
}
class FooClass implements Foo {
hello(value: string) { //notice the missing 'number'
console.log(`hello ${value}`)
}
}
const x = new FooClass()
x.hello("me")
//x.hello(42) this gives a compile error
const y: Foo = x
y.hello(42)
Run Code Online (Sandbox Code Playgroud) 我没有任何PLC的经验,但对于我将要做的下一个项目,我将不得不开发一个与PLC通信的应用程序.基本上,我将收到一条XML消息,我必须转发给PLC.我不会进行PLC代码的开发,但我想了解如何设计PLC数据结构(尽可能接近xml模式)并将消息发送到PLC.
尚未选择应用程序的编程语言,因此任何语言的示例都可以.
我可以选择指针比较或strcmp.我知道字符串永远不会超过8个字符,我的目标是64位平台.他们的表现同样出色还是其中一个会更好?我可以想象这可能在平台和编译器之间有所不同,如果是这样,我想知道有关平台/编译器细节的详细信息.
GR,
科恩
如果我使用任何内置函数或全局变量而不显式导入它,我希望我的打字稿编译器或 eslinter 会引发错误。这可以做到吗?如果可以,怎么做?
例如
//missing: import { console, process, Array } from "?"
export function print(): number[] {
console.log("Hello") //this console usage should raise an error
process.stdout.write("World!") //this process usage too
return new Array<number>() //ideally this Array constructor too
}
Run Code Online (Sandbox Code Playgroud)