Cereal Killer
Cereal Killer

Reputation: 3414

Js file load order in meteor

In meteor docs it is written that all files in project_root/lib folder are loaded first;

I have this code:

//defined in /lib/utilties.js
String.prototype.capitalize = function(){
    return this.replace(/(^|\s)([a-z])/g, function(m, p1, p2) { 
        return p1 + p2.toUpperCase();
    });
};

and this:

//defined in /client/event-helpers/form.js
Template.form.helpers({
    fieldType: function(field) {
        return 'form-' + capitalize(field)
    }
});

this doesn't work saying that capitalize is undefined; moving capitalize function in /client/event-helpers/form.js let it work; So can someone help me to understand the file load priority in meteor and why is this happening?

Upvotes: 0

Views: 505

Answers (2)

David Weldon
David Weldon

Reputation: 64342

You have interpreted the documentation correctly with respect to load order, but that isn't the issue with your code. You added capitalize to the String prototype, but you are using it like a global function. Try this instead:

return 'form-' + field.capitalize();

Upvotes: 2

Ramsay Lanier
Ramsay Lanier

Reputation: 426

I think you have misinterpreted the documents. Files in the lib directory are not loaded first. Files in the lowest subdirectories are loaded first.

Upvotes: 0

Related Questions