【发布时间】:2012-03-20 13:39:24
【问题描述】:
我目前正在学习面向对象的 Javascript,但似乎警报不起作用。这里有什么问题?
<
html>
<head>
<script>
function professor(name, myLecture){
this.name = name;
this.myLecture = myLecture;
}
professor.prototype.display = function(){
return this.name + " is teaching " + this.myLecture;
};
function subjectList(subject){
this.subject = subject;
}
subjectList.prototype.showAll= function(){
var str = " " ;
for(var i = 0 ; i<subject.length; i++ )
str+= this.subject[i].display();
return str;
};
var ListOfSubs = new subjectList([
new professor("Muy","Obprog")
]);
alert(ListOfSubs.showAll());
</script>
<body>
</body>
</head>
</html>
【问题讨论】:
-
您是否在您使用的浏览器中打开了 JavaScript 调试器并查看是否有任何错误?
-
首先确保您的 javascript 没有错误(ReferenceError: 主题未定义 - 第 17 行)
-
使用调试器...我得到的错误是“未定义主题”
-
for(var i = 0 ; i
-
@user962206 你可以浏览任何网站...控制台只是执行你的代码。这里应该有更多信息:stackoverflow.com/questions/45965/…
标签: javascript arrays oop prototype