admin管理员组文章数量:1023282
Hi I am creating a money lend tracking website using meteor. It is my first attempt to learn meteor js. I tried writing the following piece of code in my js file
var lists = new Meteor.Collection("Lists");
But when I go back in Chrome developer console after refreshing page and type
lists
ReferenceError: lists is not defined
get stack: function () { [native code] }
message: "lists is not defined"
set stack: function () { [native code] }
__proto__: Error
Is there something i am missing ? Could any one help me.
Hi I am creating a money lend tracking website using meteor. It is my first attempt to learn meteor js. I tried writing the following piece of code in my js file
var lists = new Meteor.Collection("Lists");
But when I go back in Chrome developer console after refreshing page and type
lists
ReferenceError: lists is not defined
get stack: function () { [native code] }
message: "lists is not defined"
set stack: function () { [native code] }
__proto__: Error
Is there something i am missing ? Could any one help me.
Share Improve this question edited Apr 14, 2013 at 4:14 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Apr 14, 2013 at 4:03 sreeprasadsreeprasad 3,2603 gold badges29 silver badges34 bronze badges 2-
3
Why are you refreshing the page? And where is this line of code found? You just said "in my js file". Is it in the global scope? Otherwise
lists
isn't globally available – Ian Commented Apr 14, 2013 at 4:08 - i have added this line as the first line in lendLibrary.js file. – sreeprasad Commented Apr 14, 2013 at 4:11
3 Answers
Reset to default 6You can't access lists from your web console because code is scoped with each file. In meteor your code would be run as
function() {
var lists = new Meteor.Collection("Lists");
....
}
So to access your collection in the console you need to globally scope it by changing your line to:
lists = new Meteor.Collection("Lists");
So that lists
can be used anywhere such as other files and the webkit console
Those using the book, "Getting Started with meteor.js", from which this example originates.... are instructed by the author to use the var keyword before "lists", thereby local scoping that variable and causing the mismatch between what the book says you should see and what you actually see in a browser console. This is a mistake in the book and I have been unable to find any online errata for the book.
From the book "Getting Started with Meteor.js JavaScript"
Errata type: Code| Page number: Chapter 2. Reactive Programming… It's Alive!, | Errata date: 18-4-2013
In the example:
var lists = new Meteor.Collection("Lists");
should read instead
lists = new Meteor.Collection("Lists");
The reason is that "...Meteor 0.6 has added file-level JavaScript variable
scoping. Variables declared with var at the outermost level of a JavaScript
source file are now private to that file. Remove the var to share a value
between files."
Hi I am creating a money lend tracking website using meteor. It is my first attempt to learn meteor js. I tried writing the following piece of code in my js file
var lists = new Meteor.Collection("Lists");
But when I go back in Chrome developer console after refreshing page and type
lists
ReferenceError: lists is not defined
get stack: function () { [native code] }
message: "lists is not defined"
set stack: function () { [native code] }
__proto__: Error
Is there something i am missing ? Could any one help me.
Hi I am creating a money lend tracking website using meteor. It is my first attempt to learn meteor js. I tried writing the following piece of code in my js file
var lists = new Meteor.Collection("Lists");
But when I go back in Chrome developer console after refreshing page and type
lists
ReferenceError: lists is not defined
get stack: function () { [native code] }
message: "lists is not defined"
set stack: function () { [native code] }
__proto__: Error
Is there something i am missing ? Could any one help me.
Share Improve this question edited Apr 14, 2013 at 4:14 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Apr 14, 2013 at 4:03 sreeprasadsreeprasad 3,2603 gold badges29 silver badges34 bronze badges 2-
3
Why are you refreshing the page? And where is this line of code found? You just said "in my js file". Is it in the global scope? Otherwise
lists
isn't globally available – Ian Commented Apr 14, 2013 at 4:08 - i have added this line as the first line in lendLibrary.js file. – sreeprasad Commented Apr 14, 2013 at 4:11
3 Answers
Reset to default 6You can't access lists from your web console because code is scoped with each file. In meteor your code would be run as
function() {
var lists = new Meteor.Collection("Lists");
....
}
So to access your collection in the console you need to globally scope it by changing your line to:
lists = new Meteor.Collection("Lists");
So that lists
can be used anywhere such as other files and the webkit console
Those using the book, "Getting Started with meteor.js", from which this example originates.... are instructed by the author to use the var keyword before "lists", thereby local scoping that variable and causing the mismatch between what the book says you should see and what you actually see in a browser console. This is a mistake in the book and I have been unable to find any online errata for the book.
From the book "Getting Started with Meteor.js JavaScript"
Errata type: Code| Page number: Chapter 2. Reactive Programming… It's Alive!, | Errata date: 18-4-2013
In the example:
var lists = new Meteor.Collection("Lists");
should read instead
lists = new Meteor.Collection("Lists");
The reason is that "...Meteor 0.6 has added file-level JavaScript variable
scoping. Variables declared with var at the outermost level of a JavaScript
source file are now private to that file. Remove the var to share a value
between files."
本文标签: javascriptcreating a list using meteorStack Overflow
版权声明:本文标题:javascript - creating a list using meteor - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745599455a2158370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论