0

I have two js file :

validate.js
login.js

login.js needs function in validate.js, so login.js must call after validate.js. but in meteorjs i dont know how to sort it like that. because as i know all file js in client/ will be loaded. and this is the result :

login.js
validate.js

please help how to sort thid js file?

update Okay i can sort js file now, but i cant call function from validate.js this is my validate.js :

function firstValidator(){
    this.isTextValidate = {
        text : function(text){
            return true;
        },
        password: function(password){
            return true;
        },
        date: function(date){
            return true;
        }
    }
}

and this is my login.js

var isValid = new firstValidator();
Template.cust_login.events({
    'click button':function(){
        login();

    },
    'keyup input#inputUserLogin': function () {
         alert(isValid.isTextValidate.text("text"));
    },
    'keyup input#inputUserPassword': function () {

    }

});

and it error in :

var isValid = new firstValidator();
Uncaught ReferenceError: firstValidator is not defined 

why this is happend? and how to solve this, so i can use firstValidator() in another js

1 Answer 1

3

Meteor loads files in the same directory alphabetically. Files in deeper subdirectories are loaded first. Files in a lib/ directory are loaded before everything else. Files named like main.* are loaded last. In your case I would put validate.js in client/lib/. If you want your validate file to be available on the client and the server, put it just in lib/ instead.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks @Cuberto the problem finish, but new problem happend :(
Meteor wraps files in an IIFE. This means that variables defined with a function declaration or var don't get exported to the global scope. If you want to define a global function, you need to do it without var or a function declaration: firstValidator = function() { /* ... */ };. A more explicit alternative is to pass in the global variable directly: (function( global ) { global.firstValidator = function() {}; }( this ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.