0

I have a very simple question. I'm doing the simple-todos tutorial of meteor.

I want t add a utils.js file.

For now it only has :

function foo () {
    return "text";
}

I've placed the file under myapp/client

And I'm trying to reach it from simple-todos.js, But I keep getting an error, saying foo is not defined.

How can I add a utils.js file that will be accessible by simple-todos.js?

oopsi
  • 1,919
  • 3
  • 21
  • 28
  • 1
    Possible duplicate of http://stackoverflow.com/questions/26836390/how-can-i-access-constants-in-the-lib-constants-js-file-in-meteor/26838580#26838580. To solve your issue, simply write `foo = function() {/*...*/};` – Kyll Feb 16 '15 at 13:40

1 Answers1

1

Meteor applies scoping of variables to each file, including functions. You just need to globally define it. This means don't use the var keyword when you want to access it from other files:

Instead of

function foo () {
    return "text";
}

//Which is similar to

var foo = function () {
    return "text";
}

Use:

foo = function () {
    return "text";
}
Tarang
  • 75,157
  • 39
  • 215
  • 276