Javascript で OOP を学習するための簡単なプログラムを作成しました。定義済みの文字列ステートメントを出力するだけです。ここでの問題は、プログラムがテキスト ノードを「出力 div」に直接バインドし、それらをそれぞれの「p」要素に追加する前のコマンドを無視していることです。
Student.prototype.sayHello = function()
{
var responseString = document.createTextNode("Hello, I've been waiting here for you. Student.");
return document.createElement("p").appendChild(responseString);
}
Student.prototype.sayGoodBye = function()
{
var responseString = document.createTextNode("tchau");
return document.createElement("p").appendChild(responseString);
}
var student = new Student();
document.getElementById("output").appendChild(student.sayHello());
document.getElementById("output").appendChild(student.walk());
document.getElementById("output").appendChild(student.sayGoodBye());