Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Trying to make one's tools better is always worth it. Typescript is to me the most exciting thing to have happened to JS, better than all the so called libraries that have to be declared inside a function (!!) so that the scope doesn't get completely screwed up.

The JS community is not an argument for JS I feel, because it does not have a track record of providing reliable software. Most libraries are new and a lot of devs are very lax with security or code robustness. If you use a library/tool you're not sure what you're getting - see the semicolon situation or the npm directory deletion.



> the so called libraries that have to be declared inside a function (!!)

This scope trick (and really, the whole JS language situation) always reminded me of the "closures vs. objects" koan:

http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...


as a note this works in JS too.

  var mariner= {};

  mariner.new = function(){
      var self = {};
      var maxhp = 200;
      var hp = maxhp;
      
      self.heal = function(deltahp) {
          if (hp + deltahp < maxhp){
              hp = hp + deltahp;
          } else {
              hp = maxhp;
          }
      }
      self.sethp = function(newhp) {
          if (newhp < maxhp){
              hp = newhp;
          } else {
              hp = maxhp;
          }
      }
      self.gethp = function(){
          return hp;
      }
      
      return self; 
  }

  var m1 = mariner.new();
  m1.sethp(100);
  m1.heal(13);
  alert(m1.gethp());
(shamelessly stolen from http://lua-users.org/wiki/ObjectOrientationClosureApproach)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: