TypeScript中有析构函数吗?如果没有,我该如何删除对象?我尝试过destructor()
,~ClassName()
但它没有用.
目前我正在开发一个打字稿项目,我真的很喜欢TypeScript带来的类型推断.但是 - 当从HTTP调用获取对象时 - 我可以将它们转换为所需类型,获取代码完成并在它们上编译函数编译时间,但这些会导致错误运行时
例:
class Person{
name: string;
public giveName() {
return this.name;
}
constructor(json: any) {
this.name = json.name;
}
}
var somejson = { 'name' : 'John' }; // Typically from AJAX call
var john = <Person>(somejson); // The cast
console.log(john.name); // 'John'
console.log(john.giveName()); // 'undefined is not a function'
Run Code Online (Sandbox Code Playgroud)
虽然这很好地编译 - 并且intellisense建议我使用该函数,但它给出了运行时异常.解决方案可能是:
var somejson = { 'name' : 'Ann' };
var ann = new Person(somejson);
console.log(ann.name); // 'Ann'
console.log(ann.giveName()); // …
Run Code Online (Sandbox Code Playgroud) 给出函数内的以下C#代码:
....
var documentCollection =
client.CreateDocumentCollectionQuery("dbs/" + database.Id)
.Where(c => c.Id == DocumentCollectionName)
.AsEnumerable()
.FirstOrDefault();
if (documentCollection == null)
{
documentCollection =
await
client.CreateDocumentCollectionAsync(
"dbs/" + database.Id,
new DocumentCollection { Id = DocumentCollectionName });
}
return client;
Run Code Online (Sandbox Code Playgroud)
注意:我没有返回documentCollection
,我只需要初始化,如果还没有(CreateDocumentCollectionAsync
调用).所以 - 在if
块之后,documentCollection
变成一个未使用的变量.
现在 - ReSharper建议将其优化为:
var documentCollection =
client.CreateDocumentCollectionQuery("dbs/" + database.Id)
.Where(c => c.Id == DocumentCollectionName)
.AsEnumerable()
.FirstOrDefault()
?? await
client.CreateDocumentCollectionAsync(
"dbs/" + database.Id,
new DocumentCollection { Id = DocumentCollectionName });
Run Code Online (Sandbox Code Playgroud)
并且现在表明这 …
在R中给出这样的数据帧:
+---+---+
| X | Y |
+---+---+
| 1 | 2 |
| 2 | 4 |
| 4 | 5 |
+---+---+
Run Code Online (Sandbox Code Playgroud)
如果对此数据帧执行矢量化操作,如下所示:
data$Z <- data$X * data$Y
Run Code Online (Sandbox Code Playgroud)
这会利用处理器的单指令多数据(SIMD)功能来优化性能吗?这似乎是一个完美的案例,但我找不到任何证实我的预感的东西.
我有一个角度指令的小问题,现在正在工作,我不知道为什么.我认为这是一个相当简单的问题,我忽略了,也许你可以帮助我.
指令的定义如下:
angular.module('directives', [])
.directive('my-directive', function () {
return {
restrict: 'AE',
scope: {
name: '=name'
},
template: '<h1>{{name}}</h1>'
};
});
Run Code Online (Sandbox Code Playgroud)
然后index.cshtml:
<my-directive name="test"></my-directive>
Run Code Online (Sandbox Code Playgroud)
application.js中:
var app = angular.module('MyApp', [
...,
'directives'
]);
Run Code Online (Sandbox Code Playgroud)
这里是controllers.js
angular.module('controllers', ['apiServices', 'directives'])
.controller('homecontroller', function($scope, $resource, webApiService, $log, $translate, $localStorage, $sessionStorage) {
Run Code Online (Sandbox Code Playgroud)
确认已加载directives.js,否则application.js会对'未知模块'进行唠叨.控制台中没有错误消息,事情就是没有显示.有任何想法吗?
编辑
正如所指出的,我将指令名改为camelCase,但仍然没有运气:
<my-directive name="John Doe"></my-directive>
Run Code Online (Sandbox Code Playgroud)
和
.directive('myDirective', function () {
Run Code Online (Sandbox Code Playgroud)
但还没有任何表现.
编辑
问题是angular要求将对象传递给属性,而不是字符串文字.如果您创建了一个对象person = {name:'John'},请将该人传入,然后写{{person.name}}(假设我们将属性person + scope var person命名).
一件非常简单的事情,我无法让它发挥作用.我想全局化我的DLL,因此我使用资源文件+ ResourceManager.
我将资源管理器称为:
var p = new ResourceManager("Appname.Default", Assembly.GetExecutingAssembly());
Run Code Online (Sandbox Code Playgroud)
得到这样的字符串
System.Diagnostics.Debug.WriteLine(p.GetString("greeting"));
System.Diagnostics.Debug.WriteLine(p.GetString("greeting", new CultureInfo("nl")));
System.Diagnostics.Debug.WriteLine(p.GetString("greeting", new CultureInfo("nl-NL")));
System.Diagnostics.Debug.WriteLine(p.GetString("greeting", new CultureInfo("en")));
Run Code Online (Sandbox Code Playgroud)
它返回相同字符串的4倍.我的文件被调用
Default.resx
Default.en.resx
Default.nl.resx
Default.nl-NL.resx
Run Code Online (Sandbox Code Playgroud)
所有文件设置都相同,但如上所述 - 仅使用默认文件中的资源.
我在这里俯瞰什么?
我和这个人有同样的问题:我可以通过Azure API管理服务运行SignalR集线器吗?
我似乎无法在服务中对其进行配置:它仅允许我转发HTTP / HTTPS通信。这与论坛帖子中该人的答案相符。我跟踪了到Microsoft论坛的链接,但是似乎那里没有解决这个问题。由于回应是从2014年开始,我想-也许现在有可能。
我在Ubuntu Linux 14机器上安装了ElasticSearch和Kibana边缘版本.这就是ElasticSearch 1.4.4上的Kibana 4.
通过以下方式运行和工作: ./bin/kibana
但是,一旦我断开我的Putty会话,Kibana就会停止工作.ElasticSearch继续侦听端口9200,但不再能够在5601处访问Kibana.
差异似乎是Kibana在'前景'中运行 - 因为一旦你运行它 - 你会看到日志消息一直在飞行.使用-q
会使它确实安静 - 但不能在后台运行.
所以我在某处读到在后台运行它可能会起作用:./bin/kibana &
.它没有.也没有用CTRL-Z and then bg
.
也许,原因是我在登录用户下运行Kibana,当我退出时,它会杀死该用户的所有进程.所以,我想sudo adduser kibanarunner
和sudo -u kibanarunner ./bin/kibana
,但没有做的伎俩无论是.
我希望Kibana在停止SSH会话后保持正常运行 - 我该怎么做?
我们构建了这个应用程序,需要在远程计算机(实际上是 MatLab 服务器)上完成一些计算。我们使用 Web 服务连接到 MatLab 服务器并执行计算。
为了加快速度,我们使用了Parallel.ForEach()
同时进行多个服务调用的方法。如果我们非常保守地将ParallelOptions.MaxDegreeOfParallelism
(DOP) 设置为 4 或其他值,那么一切都会运行良好。然而,如果我们让框架决定 DOP,它将产生如此多的线程,从而迫使远程计算机屈服并开始发生超时(> 10 分钟)。
我们该如何解决这个问题呢?我希望能够做的是利用响应时间来限制调用。如果响应时间小于 30 秒,则继续添加线程,一旦超过 30 秒,就减少使用。有什么建议么?
注意与此问题中的响应相关:Parallel Foreach webservice call。
c# parallel-processing multithreading task-parallel-library parallel.foreach
我希望在存储帐户上启用静态站点托管,该存储帐户由 Azure DevOps 管道中的 Azure 资源管理器 (ARM) 模板创建,但无法解析jq
ARM 输出变量。
步骤 1:创建资源组的 Azure DevOps 任务的 YML
- task: AzureResourceGroupDeployment@2
inputs:
azureSubscription: 'AzureSubscription'
action: 'Create Or Update Resource Group'
resourceGroupName: 'vue-demo-app'
location: 'West Europe'
templateLocation: 'Linked artifact'
csmFile: '$(Build.ArtifactStagingDirectory)/infra/infra.json'
csmParametersFile: '$(Build.ArtifactStagingDirectory)/infra/env-arm-params-default.json'
deploymentMode: 'Incremental'
deploymentOutputs: 'appstoragename'
displayName: 'Create or update resource group'
Run Code Online (Sandbox Code Playgroud)
日志显示如下:
##[debug]set appstoragename={"appstoragename":{"type":"String","value":"demoappstaticstore"}}
Run Code Online (Sandbox Code Playgroud)
因此,此时,有一个有效的JSON 值返回到 Azure DevOps。到目前为止,一切都很好。
步骤 2:尝试在存储帐户上启用静态网站托管的 Azure DevOps 任务
- task: AzureCLI@1
inputs:
azureSubscription: 'AzureSubscription'
scriptLocation: 'inlineScript'
inlineScript: |
echo "Enabling static website hosting …
Run Code Online (Sandbox Code Playgroud) c# ×4
javascript ×2
typescript ×2
angularjs ×1
azure ×1
azure-devops ×1
bash ×1
compilation ×1
destructor ×1
dll ×1
kibana ×1
kibana-4 ×1
linux ×1
optimization ×1
r ×1
resharper ×1
signalr ×1
simd ×1
ubuntu ×1