[Moo] Classes - need help with calling function

6 messages Options
Embed this post
Permalink
mmjaeger

[Moo] Classes - need help with calling function

Reply Threaded More More options
Print post
Permalink

Hello

I've got the following code:
var Cover = new Class({

        cover: function() {

                ????? call to setProperties function in Site Class?
        }

})

var Site= = new Class({

        var cover = new Cover();

        setProperties: function() {

        }
})

the Site Class initiates the Cover class - upon finishing the cover
function, I'd like to call the setProperties function in the Site
Class - I was trying to provide a callback function to new Cover
({callback: ....}) but that didn't work either.
What's the best way to do this.
Thank you in advance for your input.
Piotr Zalewa

[Moo] Re: Classes - need help with calling function

Reply Threaded More More options
Print post
Permalink

If your class Cover needs Site to operate then it should implement it. It will have all the methods and properties. I think the data model you're using has a "specification error". We'll be able to help you after we'd get a glimpse what are you writing and what language problem you met.
Your problem might be "fixed" with a not nice method by providing the cover parameter "this" as an argument.
var Cover = new Class({
  initialize: function (site) {
    this.site = site;
  },
  cover: function() {
    this.site.setParameters();
  }
});

And instantiate cover with
var cover = new Cover(this)

On 29 Oct 2009 01:25, "mmjaeger" <[hidden email]> wrote:


Hello

I've got the following code:
var Cover = new Class({

       cover: function() {

               ????? call to setProperties function in Site Class?
       }

})

var Site= = new Class({

       var cover = new Cover();

       setProperties: function() {

       }
})

the Site Class initiates the Cover class - upon finishing the cover
function, I'd like to call the setProperties function in the Site
Class - I was trying to provide a callback function to new Cover
({callback: ....}) but that didn't work either.
What's the best way to do this.
Thank you in advance for your input.

Piotr Zalewa

[Moo] Re: Classes - need help with calling function

Reply Threaded More More options
Print post
Permalink
Although I don't see the reason for that, but it may happen you wanted something like this: http://mooshell.net/xxMuq/ , but again - you need to provide a bigger picture.

zalun
--
London, UK
Ryan Florence

[Moo] Re: Classes - need help with calling function

Reply Threaded More More options
Print post
Permalink
In reply to this post by mmjaeger

Can you try to explain more what you're trying to do?  Typically you  
don't want one class coupled with another, they should be able to  
exist independently.

The exception of course is when you use Implements or Extends.  I  
wonder if you could explain better what you're trying to do, we could  
figure out that you simply need to extend or implement one of the  
classes with the other.


Ryan Florence

[Writing TextMate Snippets] ( http://blog.flobro.com/ )

On Oct 28, 2009, at 7:24 PM, mmjaeger wrote:

>
> Hello
>
> I've got the following code:
> var Cover = new Class({
>
> cover: function() {
>
> ????? call to setProperties function in Site Class?
> }
>
> })
>
> var Site= = new Class({
>
> var cover = new Cover();
>
> setProperties: function() {
>
> }
> })
>
> the Site Class initiates the Cover class - upon finishing the cover
> function, I'd like to call the setProperties function in the Site
> Class - I was trying to provide a callback function to new Cover
> ({callback: ....}) but that didn't work either.
> What's the best way to do this.
> Thank you in advance for your input.

anutron

[Moo] Re: Classes - need help with calling function

Reply Threaded More More options
Print post
Permalink
typically this kind of problem is handled with events. Your Cover class has an "onFoo" event, then your Site class, which instantiates Cover, attaches an "onFoo" event handler.

On Thu, Oct 29, 2009 at 7:18 AM, Ryan Florence <[hidden email]> wrote:

Can you try to explain more what you're trying to do?  Typically you don't want one class coupled with another, they should be able to exist independently.

The exception of course is when you use Implements or Extends.  I wonder if you could explain better what you're trying to do, we could figure out that you simply need to extend or implement one of the classes with the other.


Ryan Florence

[Writing TextMate Snippets] ( http://blog.flobro.com/ )


On Oct 28, 2009, at 7:24 PM, mmjaeger wrote:


Hello

I've got the following code:
var Cover = new Class({

       cover: function() {

               ????? call to setProperties function in Site Class?
       }

})

var Site= = new Class({

       var cover = new Cover();

       setProperties: function() {

       }
})

the Site Class initiates the Cover class - upon finishing the cover
function, I'd like to call the setProperties function in the Site
Class - I was trying to provide a callback function to new Cover
({callback: ....}) but that didn't work either.
What's the best way to do this.
Thank you in advance for your input.


The MooTools Tutorial: www.mootorial.com Clientcide: www.clientcide.com
mmjaeger

[Moo] Re: Classes - need help with calling function

Reply Threaded More More options
Print post
Permalink

Thanks Aaron - that's what I figured out at the end from looking at
some clientcide code.

Once again thanks everybody for helping out

On Oct 29, 8:34 am, Aaron Newton <[hidden email]> wrote:

> typically this kind of problem is handled with events. Your Cover class has
> an "onFoo" event, then your Site class, which instantiates Cover, attaches
> an "onFoo" event handler.
>
>
>
> On Thu, Oct 29, 2009 at 7:18 AM, Ryan Florence <[hidden email]> wrote:
>
> > Can you try to explain more what you're trying to do?  Typically you don't
> > want one class coupled with another, they should be able to exist
> > independently.
>
> > The exception of course is when you use Implements or Extends.  I wonder if
> > you could explain better what you're trying to do, we could figure out that
> > you simply need to extend or implement one of the classes with the other.
>
> > Ryan Florence
>
> > [Writing TextMate Snippets] (http://blog.flobro.com/)
>
> > On Oct 28, 2009, at 7:24 PM, mmjaeger wrote:
>
> >> Hello
>
> >> I've got the following code:
> >> var Cover = new Class({
>
> >>        cover: function() {
>
> >>                ????? call to setProperties function in Site Class?
> >>        }
>
> >> })
>
> >> var Site= = new Class({
>
> >>        var cover = new Cover();
>
> >>        setProperties: function() {
>
> >>        }
> >> })
>
> >> the Site Class initiates the Cover class - upon finishing the cover
> >> function, I'd like to call the setProperties function in the Site
> >> Class - I was trying to provide a callback function to new Cover
> >> ({callback: ....}) but that didn't work either.
> >> What's the best way to do this.
> >> Thank you in advance for your input.