//創(chuàng)建構(gòu)造函數(shù)
function Word(words){ this.words = words;
}
Word.prototype = {
alert(){
alert(this.words);
}
} //創(chuàng)建實(shí)例
var w = new Word("hello world");
w.print = function(){ console.log(this.words); console.log(this); //Person對(duì)象
}
w.print(); //hello world
w.alert(); //hello world{ alert(){
alert(this.words);
}
}
這個(gè)對(duì)象怎么理解?這是什么寫法?
這個(gè)對(duì)象怎么理解?這是什么寫法?
桃花長(zhǎng)相依
2019-03-04 21:10:53