1

Why does this code does not work?

function Apple (type) {
    this.type = type;
    this.color = "red";
    this.getInfo = getAppleInfo;
}

If I try to call Apple, I get the error message

Uncaught ReferenceError: Apple is not defined(…)

(anonymous function) @ VM1844:2

InjectedScript._evaluateOn @ VM1757:875

InjectedScript._evaluateAndWrap @ VM1757:808

InjectedScript.evaluate @ VM1757:664

Colas
  • 3,473
  • 4
  • 29
  • 68
  • Whe need to know more code for check scopes... where is declaration and where the invocation or call – Joaquin Javi Oct 23 '15 at 18:09
  • What do you mean by declaration? It is in a `file.js` file. I know that the code there is executed (I can log). The invocation is from the debugger. If I do `console.log(Apple);` in the js file, it works. – Colas Oct 23 '15 at 18:16
  • It seems the code of `file1.js` is executed but not "seen" by `file2.js`. – Colas Oct 23 '15 at 18:21
  • I mean in meteor there are some conventions and client server and both scopes, also theres a rule that the first file is called is main.js anyway print this inside de block where you are executing and you will know in wich scope you are , after you can play with bind method to chain.. – Joaquin Javi Oct 23 '15 at 18:24
  • See my edit of the message. – Colas Oct 23 '15 at 18:26
  • Your edit is a typo, your first issue is likely a scope issue. – Kyll Oct 23 '15 at 18:29
  • Also check this http://docs.meteor.com/#/full/structuringyourapp , so meteor have startups methods.. scope conventions ..etc.. – Joaquin Javi Oct 23 '15 at 18:35
  • @JoaquinJavi Thanks for your help!! Do you understand why the code does not work (in More code)? – Colas Oct 23 '15 at 18:36
  • Ok! it was a stupid typo!!!! – Colas Oct 23 '15 at 18:38

1 Answers1

1

If you want something global in Meteor, don't prefix with var.

So, this should work!

Apple = function (type) {
    this.type = type;
    this.color = "red";
    this.getInfo = getAppleInfo;
}
Colas
  • 3,473
  • 4
  • 29
  • 68
  • Yes, this is the answers of the targeted question. If your question is a duplicate of the targeted question you should not post an answer but validate the duplicate. – Kyll Oct 23 '15 at 18:46