oopsi
oopsi

Reputation: 2039

Add js file to meteor project

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?

Upvotes: 0

Views: 78

Answers (1)

Tarang
Tarang

Reputation: 75965

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";
}

Upvotes: 1

Related Questions