fork download
  1. function PowerPanel(type) {
  2. this.setType(type);
  3. }
  4.  
  5. PowerPanel.prototype.NIGHT_POWER = 0;
  6.  
  7. PowerPanel.typeList = {
  8. "typeOne": 1,
  9. "typeTwo": 2,
  10. "typeThree": 3,
  11. "typeFour": 4,
  12. "typeFive": 5
  13. };
  14.  
  15. PowerPanel.prototype.setType = function(type) {
  16. if (!(type in PowerPanel.typeList)) {
  17. throw new PowerPanelException("Неправильный тип панели");
  18. }
  19. this._type = PowerPanel.typeList[type];
  20. };
  21.  
  22. function PowerPanelException(message) {
  23. this.name = "PowerPanelException";
  24. this.message = message;
  25. }
  26.  
  27. function generator(name, conditions) {
  28. var objects = [];
  29. for (var key in conditions) {
  30. for (var i = 0; i < conditions[key]; i++) {
  31. objects.push(new name(key));
  32. }
  33. }
  34. return objects;
  35. }
  36.  
  37. var conditionsForPwrSt = {
  38. "typeOne": 4,
  39. "typeTwo": 0,
  40. "typeThree": 2,
  41. "typeFour": 1,
  42. "typeFive": 2
  43. };
  44. var panels = generator("PowerPanel", conditionsForPwrSt);
  45. console.log(panels);
Runtime error #stdin #stdout #stderr 0s 17128KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:31:12 TypeError: name is not a constructor