我想了解JavaScript中的一些概念。請看下面的代碼:
function Person(name, age)
{
this.name = name || "no name";
this.age = age || "age not specified";
this.printStr = function()
{
console.log("< " + this.name + ", " + this.age + " >");
};
}
p = new Person("pranav", 26);
p.printStr = function()
{
console.log("this works. also ...." + this.name);
};
p.printStr();
我想稱之爲「printStr」的Person類實現從「printStr」功能在「P」的實施範圍內。
使得輸出應該是:
< pranav, 26 >
this works. also ....pranav
任何想法? :)