This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Jason Nelson
Posted Sep 30 - Read on Facebook

Apologies for the long post:

Hello, all. Question around referencing variables from a module. If I declare a variable in the primary app.coffee file, is there an easy way to reference that variable from a module *without explicitly passing it* along when calling a function from within the module?

Example:

----------------------------------------------------------------
app.coffee:

a = "hello"

module.print_a()

module:

exports.print_a = ->
print a

----------------------------------------------------------------

Doing this, I get undefined.

I know I could modify calling the function this way and it would work:

module.print_a(a)

If I need to reference a lot of different variables though, this becomes obnoxious.

I know the following would work as well.

----------------------------------------------------------------
app.coffee:

this.a = "hello"
module.print_a()

module:

exports.print_a = ->
print window.a
----------------------------------------------------------------

This could be workable, but a little annoying to declare "this" before every variable. Is there a standard "path" to getting to these variables from a module if I just do a generic declaration?

TIA. I know this was a lot to read! :)