Javascript Math.random()在不同浏览器中使用的算法有多好?是否可以用它来生成盐和一次性密码?
random我可以使用多少位?
我最近问了一个关于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) 可以说,我想为NgForm添加方法(类)
NgForm.prototype.markAsDirty = function (): void {
let f: NgForm = this;
Util.forEach(f.form.controls, (k, v: AbstractControl) => {
v.markAsDirty(false);
});
};
Run Code Online (Sandbox Code Playgroud)
这在打字稿中是否有可能?
我知道:
但它只适用于接口,而不适用于类.