Self executing function as object property value in javascript

javascript

Solution

This is how you do it.

Often called the module pattern (more info)

var b = function () {
   var c = 'hi';
   var d = null;

   return {
     c : c,
     d : d,
     e : function () {
       // this function can access the var d in the closure.
       d = 5;
     }
   }
}();

Problem

Is it possible to have a self executing function which is an objects property value assign values to other properties in the object? e.g. - what I would like to do is this: ``` var b={ c:'hi', d:null, e:new function(){this.d=5} }; ``` But the "this" inside the new function seems to refer to b.e. Is it possible to access the b.e parent (i.e. b) from inside the function?

Original source