admin管理员组文章数量:1291176
I have a Javascript object in an external js file that looks like this:
function SomeObj() {
this.property = 0;
this.property = null;
}
SomeObj.prototype = {
methodA: function() {},
methodB: function() {}
}
In my View files, I load it like this:
<script type ="text/javascript" src="someObj.js"></script>
And in jQuery, I instantiate it like this:
<script type = "text/javascript">
var someObject = new SomeObj();
</script>
At this point. console.log
spits out the UncaughtReference error saying someObj
is not defined.
What's wrong ? Help me with this Thanks in advance
I have a Javascript object in an external js file that looks like this:
function SomeObj() {
this.property = 0;
this.property = null;
}
SomeObj.prototype = {
methodA: function() {},
methodB: function() {}
}
In my View files, I load it like this:
<script type ="text/javascript" src="someObj.js"></script>
And in jQuery, I instantiate it like this:
<script type = "text/javascript">
var someObject = new SomeObj();
</script>
At this point. console.log
spits out the UncaughtReference error saying someObj
is not defined.
What's wrong ? Help me with this Thanks in advance
Share Improve this question edited Feb 21, 2017 at 5:51 Martin Schneider 3,2684 gold badges20 silver badges30 bronze badges asked Dec 15, 2012 at 1:57 Parijat KaliaParijat Kalia 5,09512 gold badges53 silver badges78 bronze badges 9- someObj = new someObj() doesn't look good... – Christophe Commented Dec 15, 2012 at 2:00
- var someObj = new someObj(); looks better^ – daniel Commented Dec 15, 2012 at 2:01
- actually I am doing var someObj = new someObj() ; sorry, it is a typo on my part – Parijat Kalia Commented Dec 15, 2012 at 2:04
-
2
@ParijatKalia: Problem is not just
var
is that you have two variables with the same exact name. – elclanrs Commented Dec 15, 2012 at 2:05 - 2 "And in my jQuery," - What jQuery is that? – nnnnnn Commented Dec 15, 2012 at 2:12
1 Answer
Reset to default 4That is because of ambiguous naming of Variable
and Object
someObj = new someObj();
Give it a different name
var obj1 = new SomeObj();
What happens if you do this
var obj = {
a :a
}
a is not defined yet so it spits out an error
本文标签: javascriptUncaught referenceError Object is not definedStack Overflow
版权声明:本文标题:javascript - Uncaught referenceError: Object is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741515966a2382890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论