我最近问了一个关于TypeScript在JavaScript API中扩展现有原型的能力的问题(这里:使用TypeScript扩展Object.prototype).
事实证明这是一个bug,从那时起就被解决了TypeScript 0.9.0 Alpha(现在包括泛型...... GREAT :-))
在TypeScript中,接口是开放式的,因此如果查看lib.d.ts,您将找到一个定义JavaScript的Object API合约的接口.您还应该看到Object的变量声明,它定义了Object的静态函数.
为简单起见,这里它们是:
//Pulled from lib.d.ts
interface Object {
toString(): string;
toLocaleString(): string;
valueOf(): Object;
hasOwnProperty(v: string): bool;
isPrototypeOf(v: Object): bool;
propertyIsEnumerable(v: string): bool;
[s: string]: any;
}
declare var Object: {
new (value?: any): Object;
(): any;
(value: any): any;
prototype: Object;
getPrototypeOf(o: any): any;
getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor;
getOwnPropertyNames(o: any): string[];
create(o: any, properties?: PropertyDescriptorMap): any;
defineProperty(o: any, p: string, attributes: PropertyDescriptor): any;
defineProperties(o: any, properties: …Run Code Online (Sandbox Code Playgroud) 考虑以下两个公式:
=IF(SEARCH("*", A1), "true", "false")
=IF(SEARCH(CHAR(42), A1), "true", "false")
Run Code Online (Sandbox Code Playgroud)
我正在使用它来尝试检测一个单元格是否包含一个*字符,但是对于所有单元格都返回"true".我只能假设Excel看起来*像一个通配符.
你如何检测*Excel中是否存在?
Kotlin具有三种性质非常相似的类型:
VoidUnitNothing似乎他们在犯JavaScript错误:
nullundefinedvoid(0)假设他们没有陷入相同的错误中,它们的全部作用是什么,它们又有何不同?
遵循这些相当基本的指示,但这似乎不起作用.
概观
我想用import { Type } from "Module"而不是/// <reference path="..." />
结构体
-app\
-ViewModel.ts
-Program.ts
Run Code Online (Sandbox Code Playgroud)
ViewModel.ts
export module Demo {
export class ViewModel {
constructor(public test: string) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
Program.ts
import { ViewModel } from "ViewModel";
Run Code Online (Sandbox Code Playgroud)
模块'C:/ DemoApp/app/ViewModel'没有导出成员'ViewModel'.
和...
--outFile只支持'amd'和'system'模块.
目标
我希望能够引用依赖项,以便它们按顺序编译为单个文件.
请帮忙!
注意:如果我添加,"module": "system"我仍然会得到上述错误中的第一个.
注意:根据第一个解决方案,我不想丢失名称空间!
我已经按照几个示例建议在ASP.NET Core WebAPI项目中设置我的默认路由,我需要替换
app.UseMvc();
Run Code Online (Sandbox Code Playgroud)
同
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}",
defaults: new { controller = "Traders", action = "Get" });
});
Run Code Online (Sandbox Code Playgroud)
但是当我运行它默认为localhost:54321/api/values并且它应该默认为localhost:54321/Traders
怎么了?
在 Kotlin 中有一些情况,编译器会抱怨定义为<T>和期望的泛型类型参数<T : Any>。有什么不同?
考虑以下Win32 API结构:
typedef struct _SECURITY_ATTRIBUTES {
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
Run Code Online (Sandbox Code Playgroud)
将此对象移植到C#时,我应该遵循此处使用的名称命名约定,如下所示:
public struct _SECURITY_ATTRIBUTES
{
public int nLength;
public unsafe byte* lpSecurityDescriptor;
public int bInheritHandle;
}
Run Code Online (Sandbox Code Playgroud)
或者我可以全力以赴,并以C#样式编写我的结构,如下所示:
public struct SecurityAttributes
{
private int length;
private unsafe byte* securityDescriptor;
private int bInheritHandle;
public Int32 Length
{
get { return this.length; }
set { this.length = value; }
}
public Byte* SecurityDescriptor
{
get { return this.seurityDescriptor; }
set { this.securityDescriptor = value; }
}
public …Run Code Online (Sandbox Code Playgroud) 什么是这个JavaScript的TypeScript等价物?
(function() {
/* code here */
})();
Run Code Online (Sandbox Code Playgroud)
我试过这个
() => {
/* code here */
}
Run Code Online (Sandbox Code Playgroud)
但这会产生
(function() {
/* code here */
});
Run Code Online (Sandbox Code Playgroud)
我需要在末尾添加额外的括号来执行匿名函数.
在使用实例成员时,我总是明确地使用我的代码,在它们前面this.加上静态成员,并在前面添加类型名称.
罗斯林似乎不喜欢这一点,并礼貌地建议你可以省略this.,并Type.从你的代码在适当情况下...
......所以我会这样做... (没有双关语意)
public void DoSomethingCool()
{
this.CallAwesomeMethod();
CoolCucumber.DoSomethingLessAewsome();
}
Run Code Online (Sandbox Code Playgroud)
... roslyn建议我这样做......
public void DoSomethingCool()
{
CallAwesomeMethod();
DoSomethingLessAwesome();
}
Run Code Online (Sandbox Code Playgroud)
...但是当谈到使用扩展方法时,似乎我不能省略this.例如...... 的使用
public int GetTotal()
{
// This doesn't work
return Sum(o => o.Value);
// This does
return this.Sum(o => o.Value);
}
Run Code Online (Sandbox Code Playgroud)
问题:
this.和Type.?this.用于扩展方法?this.和Type.和了StyleCop的分析仪坚持,我使用它们?我想构建一个检测对象更改的代理:
代码示例 1 -defineProperty
const me = {
name: "Matt"
}
const proxy = new Proxy(me, {
defineProperty: function(target, key, descriptor) {
console.log(`Property ${key} defined.`);
return Object.defineProperty(target, key, descriptor);
}
});
proxy // { name: 'Matt' }
proxy.name = "Mark";
// Property name defined.
// Mark
proxy.age = 20;
// Property age defined.
// 20
Run Code Online (Sandbox Code Playgroud)
代码示例 1 - 观察
proxy有一个属性name,这是我所期望的。name属性告诉我name已定义;不是我所期望的。age属性告诉我age已经定义;正如我所料。代码示例 2 - …