如何写好代码

题目

https://www.zhihu.com/question/39430220

如何改善如下代码

for (items) {
  item[..] =
  // or
  if () {
    return item
  }
}
s : string = 'thanks ' 
if () {
  s = s + name
  s = s + ' for purchasing
  if () {
    s = s + quantity
    s = s + product
  }
}
s = s + ..

https://zhuanlan.zhihu.com/p/64354422

class DataItem {
  constructor(id, name, value) {
    this.id = id;
    this.name = name;
    this.value = value;
  }
}

class DataCollection {
  constructor() {
    this.items = new Array();
  }
  insert(item) {
    this.items.push(item);
  }
}

const item1 = new DataItem(1, 'name1', 100);
const item2 = new DataItem(2, 'name2', 200);
const list = new DataCollection();
list.insert(item1);
list.insert(item2);
...

Powered by Jekyll and Theme by solid

本站总访问量