[Javascript] accessing nested functions

Pedro Mpa mail.pmpa at sapo.pt
Sun Jul 8 12:49:31 CDT 2007


>var f = new a();
>var g = new f.b();
>g.c();

Which is the same as:

var f = new a();
a.b();
a.b.c();

that is, just by calling a.b() then I can call a.b.c(), as I previously
noticed.

I'm going to try object literals like you said.
Brian, what I meant by PHP behaviour is the class->func , so I thought that
in JS I could do class->func->func->... 

Thanks.


-----Original Message-----
From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu]
On Behalf Of Noah Sussman
Sent: domingo, 8 de Julho de 2007 15:02
To: [JavaScript List]
Subject: Fwd: [Javascript] accessing nested functions

On 7/6/07, Pedro Mpa <mail.pmpa at sapo.pt> wrote:
> I'm having some trouble accessing nested functions, like in the following
> example, how can I access function c ?
>
> function a(){
>         this.vara = "";
>
>         this.b = function(){
>                 this.varb = "";
>
>                 this.c = function(){
>                         this.varc = "";
>                         alert('something');
>                 }
>         }
> }

var f = new a();
var g = new f.b();
g.c();

You might also want to experiment with object literals, such as:

var a = {
 vara : '',
 b : {
  varb : '',
  c : function () {
    varc : '',
    alert('something');
  }
 }
}


a.b.c();
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript






More information about the Javascript mailing list