I have the 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 that = 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 - what I was trying to achieve was to create a list of types which would be objects created from the same prototype (typeObj) and having their own properties. These types would be available in media.types hence the self executing function returns all these types.
The only problem is - this self-executing function has to refer to the parent (so media) to be able to access it's data property. I tried to call that anonymous function passing THIS as an argument then using parent variable inside it but parent is undefined.
My question is - is there any other way to be able to refer to parent object inside that self executing function?