fork(1) download
  1.  
  2. function Acid(){
  3. this.hydrogen = null;
  4. this.rest = null;
  5.  
  6. function namedAcid(name){
  7. this.hydrogen = name.substring(0, 1);
  8. this.rest = name.substring(2);
  9. }
  10.  
  11. function specifedAcid(hydrogen, rest){
  12. this.hydrogen = hydrogen;
  13. this.rest = rest;
  14. }
  15.  
  16. switch(arguments.length){
  17. case 1:
  18. namedAcid(arguments[0]);
  19. break;
  20. case 2:
  21. specifedAcid(arguments[0], arguments[1]);
  22. break;
  23. }
  24. }
  25.  
  26. Acid.prototype.printAcid = function(){
  27. print("Hydrogen part: " + this.hydrogen);
  28. print("Acid rest part: " + this.rest);
  29. print("Full acid name: " + this.hydrogen + this.rest);
  30. };
  31.  
  32. var h2so4 = new Acid("H2", "SO4");
  33. var h2so3 = new Acid("H2SO3");
  34.  
  35. h2so4.printAcid();
  36. h2so3.printAcid();
Success #stdin #stdout 0.02s 30320KB
stdin
Standard input is empty
stdout
Hydrogen part: null
Acid rest part: null
Full acid name: nullnull
Hydrogen part: null
Acid rest part: null
Full acid name: nullnull