小编shi*_*iva的帖子

TypeScript 中哪种对象实例创建方式最快?

我有以下 3 种不同的方法来创建对象实例。

我想知道其中哪一个更快,占用的内存更少,为什么?

//Option 1        
export interface Animal1 {
    name: string;
    color: string;
    isHungry: boolean;
}
let animal: Animal1 = {
    name: 'cat',
    color: 'brown',
    isHungry: true
};

//Option 2   
export class Animal2 {
    name: string;
    color: string;
    isHungry: boolean;
}
let animal2: Animal2 = new Animal2();
animal2.name = 'cat';
animal2.color = 'brown';
animal2.isHungry = true;
     
//Option 3   
export class Animal3 {
    constructor(public name:string, public color:string, public isHungry:boolean) {}
}
let animal3 = new Animal3('cat', 'brown', true);
Run Code Online (Sandbox Code Playgroud)

就编码风格和维护而言,我更喜欢在单元测试中使用构建器类的选项 1。选项 …

javascript typescript

5
推荐指数
1
解决办法
2278
查看次数

这个比较器C#语法如何工作?

我看到以下语法:

var comparer = Comparer<TItem>.Default;
Run Code Online (Sandbox Code Playgroud)

这种语法如何工作?

Comparer原本以为必须是新手

.net c# generics c#-4.0

4
推荐指数
1
解决办法
60
查看次数

如何在模拟组件上模拟指令

我正在对一个包含clarity带有clarit directives.

我已经模拟了清晰度标签,但它们有clrDgItems我无法用指令类模拟的指令。

<clr-dg-row *clrDgItems="let item of items$ | async | filter : listFilter.keyword : ['trackingCode', 'title']" [clrDgItem]="episode">
Run Code Online (Sandbox Code Playgroud)

我可以替换clrDgItemsngFor,但表过滤器停止工作。

如果没有它,测试将无法编译:

无法绑定到“clrDgItemsOf”,因为它不是“clr-dg-row”的已知属性

当我将mockDirective添加为:我收到错误

失败:模块“DynamicTestModule”声明了意外值“[object Object]”

     function MockDirective(options: any): Directive {
         const metadata: Directive = {
         selector: options.selector,
         inputs: options.inputs,
         outputs: options.outputs
      };
      return new Directive(metadata);
    }

 TestBed.configureTestingModule({
      imports: [
        RouterTestingModule
      ],
      declarations: [
        MockDirective({
          selector: '[clrDgItemsOf]',
        }),
      MockComponent({
      selector: 'clr-dg-row',
      template: '<ng-content></ng-content>',
      outputs: ['clrDgItemsOf'],
      inputs: ['clrDgItem']
    }), ...
Run Code Online (Sandbox Code Playgroud)

有什么建议么?

unit-testing clarity angular

1
推荐指数
1
解决办法
5955
查看次数

哪个集合没有实现 IEnumerable

是否有任何类型的集合System.Collections不继承自IEnumerableIEnumerable<T>

我需要一个例子。

.net c# collections ienumerable

0
推荐指数
1
解决办法
1856
查看次数