0

したがって、基本的にダミーのマスター オブジェクトを作成し、プロトタイプ プロパティを介してそのすべての子にプロパティを追加しました。しかし、もちろんそれは空のプロパティです。演算子を使用して条件付きチェックを実行しin、オブジェクトに新しいプロパティがあるかどうかを確認しているときに、false であることが判明し、"Nothing there." が出力されました。これは、プロパティにまだ値がないためですか?

function Master(age, sex, location)
{
    this.age = age;
    this.sex = sex;
    this.location = location;
}

var me = new Master(99, "Male", "Texas, USA");

Master.prototype.username;


if("username" in me)
{
    document.write("The prototype put the property there.");
}
else
{
    document.write("Nothing there.<br />");
}
4

1 に答える 1