0

I'm working with 3 different files:

  • [root]/client/js/welcome.js
  • [root]/client/js/ups.js
  • [root]/client/js/main.js (I also renamed it xxx.last.js)

Code:

//welcome.js
function Welcome(){
    console.log("main");
}

Welcome.prototype.constructor = Welcome;


Welcome.prototype.displayPage = function(page){
    var jQ_page = $("#" + page);
    var title = jQ_page.attr("data-tile");
    $("#main").css("display", "none");
    jQ_page.css("display", "block");
    document.title = title;
};

//ups.js
function Ups(){
    this.query = {};
    this.creteria = {sort: {JB_owner: 0}, limit: 500, skip: 0, fields: {ClusterId: 0}};
    console.log("UPS");
}

Ups.prototype.constructor = Ups;

Meteor.startup(function() {
    var mainObj = new Welcome();        
    var UpsObj = new Ups();

    $(document).ready(function() {
    ...
    ...
    ...   
    });
});

Welcome and Ups are undefined and I don't understand why, all three files are being loaded and according meteor Docs that should works but it doesn't, any hint or help?

thanks!

1
  • Welcome.prototype.constructor = Welcome; I'm don't usually extend the prototypes but that line seems like you are assigning something to itself. Commented Aug 8, 2014 at 19:33

1 Answer 1

2

From Meteor docs

When declaring functions, keep in mind that function x () {} is just shorthard for var x = function () {} in JavaScript.

Which means that you are scoping your functions to the file, rather than the app. Try this instead.

Welcome = function () {
    console.log("main");
};

Ups = function () {
    this.query = {};
    this.creteria = {sort: {JB_owner: 0}, limit: 500, skip: 0, fields: {ClusterId: 0}};
    console.log("UPS");
};
Sign up to request clarification or add additional context in comments.

1 Comment

I don't think so. The only thing that's changed is the scope of the constructor functions.

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.