[英]Why can't I set this variable in an object with an object with javascript?
為什么我不能這樣做我不明白?
function hello() {
this.say = 'fdfsd';
}
function goodbye() {
this.example = new hello();
}
但是,如果我這樣做,它會起作用;
function hello() {
this.say = 'fdfsd';
}
function goodbye() {
this.example = false;
}
var goodbye = new goodbye();
goodbye.example = new hello();
你要goodbye
var x = new goodbye();
調用構造函數將創建一個新對象(類型為goodbye
)。
該行將構造一個hello
類型的對象,並將其分配給goodbye
實例的example
屬性
this.example = new hello();
構建之后,這就是goodbye
實例所包含的內容
// x
{
example: {
say: "fdfsd"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.