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

Functions are objects, and you can attach properties to them.

  function foo() {}
  foo.bar = 7;
  console.log(foo.bar); // prints 7


I stand corrected on not being able to attach properties to a function, but what I said still holds true. The keyword this refers to the object that owns the method. The original commenter was saying that it was the method itself that was what this points at.

letsdrive = myRide.drive window.model = 'mercedes'; letsdrive.model = 'bmw';

letsdrive(); // outputs mercedes




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

Search: