0

I have got this program(simplified from my actual program) where I am unable to access all variable from the method of the object passed to view, though I can access it from get. Am I missing something here?

all = ['hello', 'world']


require('zappajs') ->
    @get '/foo': -> 
        console.log all
        @render 'foo'

    @view foo: -> 
        console.log all

I get an exception, all not defined when run using coffee hello.coffee.

Musa
  • 96,336
  • 17
  • 118
  • 137
  • 1
    I seem to have figured out the reason after debugging it in node debugger. This view function is passed to coffeecup engine and it creates a new function with my view function embedded using 'new Function'. Creating a function this way doesnt create a closure. It would be great if someone can confirm :-) – Haraakiri Yaar Jun 16 '13 at 06:03

1 Answers1

0

In API references:

@view path: contents

Define an inline template. It’s like you had a file on disk at path inside Express’ views directory. It will have precedence over a template on disk.

Since "It’s like you had a file on disk at path inside Express’ views directory", so everything under @view is in a separate file/module, which explains why you cannot access all.

Community
  • 1
  • 1
weakish
  • 28,682
  • 5
  • 48
  • 60