Javascript 消除角函数的副作用
我正在制作一个接收两个参数的方法,Javascript 消除角函数的副作用,javascript,angular,unit-testing,typescript,side-effects,Javascript,Angular,Unit Testing,Typescript,Side Effects,我正在制作一个接收两个参数的方法,选项和数据,但是在返回值中只返回选项,我想在这个项目上实施单元测试,我想避免这个方法的副作用,我想知道这是最好的方法,返回一个数组,每个数组有两个值,或者将此方法拆分为两个返回不同值的小方法 这是我简化的演示方法: private setEst(data, options): object { const numCols: number = data.getColNumber(); const indxRows: Array<Nu
选项
和数据
,但是在返回值中只返回选项
,我想在这个项目上实施单元测试,我想避免这个方法的副作用,我想知道这是最好的方法,返回一个数组,每个数组有两个值,或者将此方法拆分为两个返回不同值的小方法
这是我简化的演示方法:
private setEst(data, options): object {
const numCols: number = data.getColNumber();
const indxRows: Array<Number> = data.getIndexRows();
const otherArray: : object[] = [];
// Creating options output that will be returned
for (let col = 1; col < numCols; col++) {
// Do something with options to modify the value of this param
...
// Read data to create an array that will be used by the next process
otherArray.push({
id: data(col).getId();
});
}
}
// Output data as a side effect
indxRows.forEach(indx => {
for (let col = 1; col < numCols; col++) {
// Do something with data object and otherArray const,
// data is modified and returned as side effect...
...
}
});
return options;
}
private setEst(数据、选项):对象{
const numCols:number=data.getColNumber();
const indxRows:Array=data.getIndexRows();
常量otherArray::对象[]=[];
//创建将返回的选项输出
for(设col=1;col{
for(设col=1;col