Question

There is a functions.js file located in src/lib/ and there is a function in it. That file has been included into slug.json.

How could we call that function inside the controller?

Was it helpful?

Solution

In coffeescript each file is wrapped with an anonymous function to avoid leaking into global scope. If you want to leak into global scope on purpose, you need to put the function in "window":

window.check_pants = (size) ->
  "No pants are too tight"

You can then call the function in the controller as "check_pants", that is to say that callers don't need to include "window".

Since "this" refers to window by default, you can use an "@" sign:

@check_slants = (size) ->
  "Too slanted"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top