class product { total : number = 0 ; ary : Array < number > = [ ] ; param { Array < number > } . . index constructor ( [ ... index ] ) { for ( let i = 0 ; i < index . length ; i ++ ) { this . total += index [ i ] ; this . ary . push ( index [ i ] ) ; } } /**
     * 返回总和
     */ Sum ( ) { return this . total ; } /**
     * 返回数据的乘积
     */ product ( ) { let total = 1 ; for ( let n = 0 ; n < this . ary . length ; n ++ ) { total *= this . ary [ n ] ; } return total ; } }