@VuuRWerk: you are partially correct about {} but when you are defining a
property in an object 'this' keyword refers to the current scope the object
is being created in and not the object itself, because the object doesn't
technically exist yet.

@websam: is it possible to show how you initialize the class and how
'myFunc' is called. It is very hard to solve your issue without that
information. Your above code looks fine by itself.

Just a tip, Mootools will automatically add 'px' to styles for you, so the (
+ 'px' ) isn't needed. Its helpful if your doing a lot of calculations to
make your code more readable.

Nathan

On Sat, Oct 25, 2008 at 3:01 PM, VuuRWerK <[EMAIL PROTECTED]> wrote:

>
> The keyword 'this' inside your styles-object relates to the styles-
> object himself and not to your class where your options are defined.
> Every { } is a new object with own properties, functions and 'this'.
>
> Following should work:
> myFunc: function() {
>    var w = this.options.width;
>    var h = this.options.height;
>     this.myDiv = new Element('div', {
>        styles: {
>             'width': w + 'px',
>            'height': h + 'px'
>        }
>    });
> }
>
> Regards
> VuuRWerK ;)
>
> On 25 Okt., 13:19, websam <[EMAIL PROTECTED]> wrote:
> > Hi there,
> >
> > I have created a class with som default options :
> >
> > var myClass = new Class({
> >         Implements: [Options, Events],
> >
> >         options: {
> >                 width: 600,
> >                 height: 400
> >         },
> >
> >         initialize: function(options){
> >                 this.setOptions(options);
> >         },
> >
> >         myFunc: function(){
> >                 this.myDiv = new Element('div', {
> >                         styles: {
> >                                 'width': this.options.width + 'px',
> >                                 'height': this.options.height + 'px'
> >                         }
> >                 });
> >         }
> >
> > });
> >
> > This is just an example but when i do this.options.width/
> > this.options.height on the new element, without setting the options
> > when i call the class, the width/height is undefined. What am i doing
> > wrong here ?
>

Reply via email to