Hello, below you will find two objects, background and photo1, which I need help cleaning up a bit. This will eventually be imported using Json but for now during development it sits as is in my script. I need help with a couple things:

- You will notice the 'val' property is identical in both objects. How can I move this into an outside function that each object can share? I'm having trouble bc I couldn't get 'this' to work outside of its current context.

- Second, how can I restructure this so that I can instantiate a new object. So if I wanted to add a new layer I'd like to do something like importLayers.push[new Layer('photo2')]

Code:
        var importLayers = {
            background: {
                layerType: 'background',
                index: 0,
                layerContent: {
                    content: function() {
                        return $(element).find('#background_Content');
                    },
                    width: 850,
                    height: 530,
                    xPos: 0,
                    yPos: -150,
                    skewX: 0,
                    skewY: 0,
                    angle: 0,
                    originX: function() { return (this.sWidth() / 2); },
                    originY: function() { return (this.sHeight() / 2); },
                    scaleX: 1,
                    scaleY: 1,
                    sWidth: function() { return this.width * this.scaleX; },
                    sHeight: function() { return this.height * this.scaleY; },
                    aspect: 0,
                    opacity: 100,
                    val: function(prop, val) {
                        switch(prop)
                        {
                            case 'width':
                                if(plugin.constrain)
                                    this.scaleX = this.scaleY = val / this.width;
                                else
                                    this.scaleX = val / this.width;
                                break;    
                            case 'height':
                                if(plugin.constrain)
                                    this.scaleY = this.scaleX = val / this.height;
                                else
                                    this.scaleY = val / this.height;
                                break;
                            case 'angle':
                                this.angle = val;    
                        }
                        buildTransformation(this, this.content());
                    }                    
                },
            },
            photo1: {
                layerType: 'photo',
                index: 1,
                layerContent: {
                    content: function() {
                        return $(element).find('#photo1_Content');
                    },
                    width: 1920,
                    height: 1280,
                    xPos: 0,
                    yPos: 0,
                    skewX: 0,
                    skewY: 0,
                    angle: 0,
                    originX: function() { return (this.sWidth() / 2); },
                    originY: function() { return (this.sHeight() / 2); },
                    scaleX: .15625,
                    scaleY: .15625,
                    sWidth: function() { return this.width * this.scaleX; },
                    sHeight: function() { return this.height * this.scaleY; },
                    aspect: 0,
                    opacity: 100,
                    val: function(prop, val) {
                        switch(prop)
                        {
                            case 'width':
                                if(plugin.constrain)
                                    this.scaleX = this.scaleY = val / this.width;
                                else
                                    this.scaleX = val / this.width;
                                break;    
                            case 'height':
                                if(plugin.constrain)
                                    this.scaleY = this.scaleX = val / this.height;
                                else
                                    this.scaleY = val / this.height;
                                break;
                            case 'angle':
                                this.angle = val;    
                        }
                        buildTransformation(this, this.content());
                    }
                },
            }
        }