3

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.

怎么了 ?帮助我提前谢谢

4

1 回答 1

4

这是因为 和 的命名不Variable明确Object

someObj = new someObj();

给它一个不同的名字

var obj1 = new SomeObj();

如果你这样做会发生什么

var obj = {
   a :a
}

a 尚未定义,因此它会吐出一个错误

于 2012-12-15T02:01:46.210 回答