Hacker News new | ask | show | jobs
by z3t4 4009 days ago
About referencing "this": It can be very useful when writing object constructors, if you always reference an object with the constructor's name.

  function Foo() {
    var foo = this;
    foo.bar = 1;
    foo.az = 2;
  }

  var foo = new Foo();
  foo.bar = foo.bar + 5;
Then it will be super easy to rename say foo.bar to something else. It's also self "documented".