List Info

Thread: Another simple OO Problem




Another simple OO Problem
user name
2008-01-21 13:17:42
In the below code, one behaviours object is shared between
all popup
objects when what I'd like is for each popup object, and in
fact each
complexDOM object, to have it's own behaviours object.

If I move this.behaviours = new Behaviours(); to the Popup()
function,
then each popup object then get's it's own Behaviours object
as I'd
like.  However, I need to declare it in complexDOM, since
all
complexDOM's will have behaviours.  Can anyone tell me why
this is not
working as I expect, and what the solution is?

function Behaviours () {
        this.array = new Array();
}

        Behaviours.prototype.push(el, event, method) =
function() {
                this.array.push({el, event, method});
        }

function complexDOM () {
        this.behaviours = new Behaviours();

}

function Popup () {
        this.options...
}

        Popup.prototype = new complexDOM();

I also found that I was unable to use the below - when
trying to loop
through this in the list function, 'this' didn't have an
array data
structure:

function Behaviours () {}
        Behaviours.prototype = new Array();
        Behaviours.prototype.list = function() {
                this.each(function(behaviour) {...});
        }


Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Another simple OO Problem
user name
2008-01-21 13:21:12
May you need to 'bind'?

       Behaviours.prototype.list = function() {
               this.each(function(behaviour) {...});
       }.bind(this);

Just a quick thought..

On Jan 21, 2008 8:17 PM, iporter <isportergmail.com> wrote:
>
> In the below code, one behaviours object is shared
between all popup
> objects when what I'd like is for each popup object,
and in fact each
> complexDOM object, to have it's own behaviours object.
>
> If I move this.behaviours = new Behaviours(); to the
Popup() function,
> then each popup object then get's it's own Behaviours
object as I'd
> like.  However, I need to declare it in complexDOM,
since all
> complexDOM's will have behaviours.  Can anyone tell me
why this is not
> working as I expect, and what the solution is?
>
> function Behaviours () {
>         this.array = new Array();
> }
>
>         Behaviours.prototype.push(el, event, method) =
function() {
>                 this.array.push({el, event, method});
>         }
>
> function complexDOM () {
>         this.behaviours = new Behaviours();
>
> }
>
> function Popup () {
>         this.options...
> }
>
>         Popup.prototype = new complexDOM();
>
> I also found that I was unable to use the below - when
trying to loop
> through this in the list function, 'this' didn't have
an array data
> structure:
>
> function Behaviours () {}
>         Behaviours.prototype = new Array();
>         Behaviours.prototype.list = function() {
>                 this.each(function(behaviour) {...});
>         }
>
>
> Thanks!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Another simple OO Problem
user name
2008-01-21 20:23:26


On Jan 22, 5:17 am, iporter <ispor...gmail.com> wrote:
> In the below code, one behaviours object is shared
between all popup
> objects when what I'd like is for each popup object,
and in fact each
> complexDOM object, to have it's own behaviours object.

You could do worse that start by reading some of Douglas
Crockfords
articles:

<URL: http:
//javascript.crockford.com/javascript.html >

<URL: http
://javascript.crockford.com/inheritance.html >

Then try posting to comp.lang.javascript[1] with questions. 
Once you
understand how javascipt inheritance works and how to use
it, you can
then choose which design patterns and libraries suit a
particular task
best.

Good luck!  


1. <URL: http://groups.google.com.au/group/comp.lang.j
avascript/topics?hl=en
>

 --
Rob


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )