1. 程式人生 > >What does the following mean as a nameTest2: () => void = null and nameTest3: () => void

What does the following mean as a nameTest2: () => void = null and nameTest3: () => void

Javascript裡有如下的寫法,可以用在定義方法時,或者定義方法時用在方法的引數上,非常靈活

// What does the following mean as a type: () => void = null
https://stackoverflow.com/questions/41868693/what-does-the-following-mean-as-a-type-void-null

  • 定義方法時
export class ExcelOperationA {
  constructor() {}
  public exportExcelA: ()
=>
void; } import { createXlsx } from './create-xlsx'; import { ExcelOperationA } from './ExcelOperationA'; @Component({ selector: 'app-classNameB', templateUrl: './ClassNameB.html' }) export class ClassNameB { constructor( public excelOperationA: ExcelOperationA ) { this.excelOperationA.exportExcelA
= () =>
createXlsx(parameterA); } } @Component({ selector: 'rms-pt', templateUrl: `<app-classNameB [datas]="datas"></app-classNameB>` }) export class RmsPtComponent { public datas: Data[] = []; constructor(private public excelOperationA: ExcelOperationA) {} public excelDownloadHandle() { this
.excelOperationA.exportToExcel(); } }