javascript self executing function as a property of object -


this question has answer here:

i have following object

    media = {     data: { files: []},     types: (function(parent)     {         var typeslist = { image: 10, epc: 1, pdf: 5, floor_plan: 10, video: 1 };          var typeobj = {              remaining: function()             {                 var = this;                  return that.limit - parent.data.files.filter(function(element)                 {                     return element.type == that.name;                 }).length;             }         }          var alltypes = {};          $.each(typeslist, function(index, element)         {             alltypes[index] = object.create(typeobj, {                   limit: { writable: false,  configurable: false, value: element }             });         });          return alltypes;      })(this), 

now - trying achieve create list of types objects created same prototype (typeobj) , having own properties. these types available in media.types hence self executing function returns these types.

the problem - self-executing function has refer parent (so media) able access it's data property. tried call anonymous function passing argument using parent variable inside parent undefined.

my question - there other way able refer parent object inside self executing function?

var data = { files: []}; media = {     data: data,     types: (function()     {         var typeslist = { image: 10, epc: 1, pdf: 5, floor_plan: 10, video: 1 };          var typeobj = {              remaining: function()             {                 var = this;                  return that.limit - data.files.filter(function(element)                     {                         return element.type == that.name;                     }).length;             }         }          var alltypes = {};          $.each(typeslist, function(index, element)         {             alltypes[index] = object.create(typeobj, {                  limit: { writable: false,  configurable: false, value: element }             });         });          return alltypes;      })(), 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -