Re: Multifile extensions with global variables that are not constant
- From: "Jasper St. Pierre" <jstpierre mecheye net>
- To: Amy C <mathematical coffee gmail com>
- Cc: gnome-shell-list gnome org
- Subject: Re: Multifile extensions with global variables that are not constant
- Date: Mon, 14 May 2012 11:50:48 -0400
On Mon, May 14, 2012 at 2:12 AM, Amy C <mathematical coffee gmail com> wrote:
> I'm writing an extension with multiple .js files, but where some need
> access to variables in others. These variables are not constant.
>
> As an example, in the main `extension.js`, imagine the following occurs:
>
> // load the other .js files, theme.js & toon.js
> const Theme = Extension.theme;
> const Toon = Extension.toon;
>
> var theme = new Theme.Theme();
> var toons = [];
> for ( let i=0; i<10; ++i ) {
> toons.append( new Toon.Toon() );
> }
>
> In my situation, the Toon.Toon class needs access to the 'theme'
> variable to get some information from it.
> However if I just use 'theme.[property]' from within toon.js without
> declaring theme first, this is a syntax error (understandably).
>
> Is the only way to give the `Toon.Toon` class access to `theme` to
> provide it in the initialiser?:
> toons.append( new Toon.Toon(theme) );
That's what I would do.
> Or is it possible to put in the toon.js file something like
> const GLOBAL = (????); // any variables that are shared between
> files live here
> and then have `theme.js` populate `GLOBAL.theme` with a pointer to the
> `theme` object, and have `toon.js` access (the updated!)
> `GLOBAL.theme`?
>
> cheers.
> _______________________________________________
> gnome-shell-list mailing list
> gnome-shell-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-shell-list
--
Jasper
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]