0

I have the following code:

function timeLine (wrapper,slider,boxwidth,labels,labelWdth) {
    this.wrapper = wrapper;
    this.slider = slider;
    this.boxwidth = boxwidth;
    this.labels = labels;
    this.labelWdth = labelWdth;

    this.setupBlocks = function(){          
        $(this.wrapper+' .blocks').each(function(){
            // Get longest block for some reason this causes us problems!
            newWidth = $(this).data('cover') * this.boxwidth;

            $(this).width(newWidth+'px');
            $(this).css('margin-left',$(this).data('left') * this.boxwidth+'px');
        })  
    }

The problem I am finding is that the this.boxwidth variable within the setupBlocks function is returning NULL.

If I defined these properties at a function level shouldn't this.variable still be available?

I guess the jQuery each is overwriting that, so how can I set the this. list as completely global?

I thought you had to have this for JS classes in this format (as per http://www.phpied.com/3-ways-to-define-a-javascript-class/ which I was using as I normally don't do Classes with JS).

Aziz
  • 7,685
  • 3
  • 31
  • 54
uk2016
  • 21
  • 4

0 Answers0