我对 JavaScript 很陌生,我正在通过教程来熟悉自己。我一直得到 12 的名称,但我觉得它应该是默认名称(因为它从未更新过)。这是非常基本的,但我找不到错误。另外,我确定我在 require 中使用了错误的函数,但我不确定该怎么做。
我应该注意到 Person.js 是在服务器上,而 PersonEmployee.html 是本地的。
PersonEmployee.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>Dojo Check</title>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.9.0/dojo/dojo.js"></script>
<script>
require(["http://www.pcs.cnu.edu/~wtaylor/Sandbox/Inheritance2/Person.js"], function(){
var aPerson = new Person("Tommy", 12, "Da Hood");
var emp = new Employee(12);
alert(emp.name);
});
</script>
</head>
<body>
</body>
</html>
人.js:
dojo.declare("Person", null,{
name: "John Doe",
age: 0,
address: "",
constructor: function(name, age, address) {
this.name = name;
this.age = age;
this.address = address;
}
});
dojo.declare("Employee", Person, {
id : 0,
constructor: function(id) {
this.id = id;
}
});