Loading ...
Sorry, an error occurred while loading the content.

Re: new function ()

Expand Messages
  • pauanyu
    ... Ah, so it has to do with more efficient memory management. I continue to be amazed how powerful the return {} construct is. At any rate, thanks for
    Message 1 of 3 , Jun 2, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      >
      > The object will always have the new function's prototype in its
      > inheritance chain, which will be linked to the function. Every
      > time you make another foo, you are going to make another function
      > object and prototype object, and prevent them from being garbage
      > collected.
      >
      > There's no point to that, particularly when you have better forms like
      >
      > var foo = (function () {
      > return {
      > bar: 1;
      > };
      > }());
      >
      > or even better
      >
      > var foo = {
      > bar: 1
      > };
      >

      Ah, so it has to do with more efficient memory management. I continue to be amazed how powerful the "return {}" construct is. At any rate, thanks for explaining.
    Your message has been successfully submitted and would be delivered to recipients shortly.