作者icydream (巧虎)
看板Ajax
標題Re: [問題] json function prototype
時間Thu Dec 24 19:46:07 2015
※ 引述《qas612820704 (Lego)》之銘言:
: var Item = {
: list: function() {
: var obj = function() {};
: obj.prototype.sayHello = function() {console.log('Hello')};
: return obj;
: },
: };
: var a = new Item.list();
: 我想請問 為何 我沒辦法 call 到 a.sayHello()
: 我不知道這該怎下關鍵字去 google 有大大可以解答媽QQ~
建議可改成
var Item = {
list: function() {
this.constructor.prototype.sayHello = function() {console.log('Hello')};
}
};
var a = new Item.list();
a.sayHello();
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.70.202.200
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Ajax/M.1450957569.A.0F0.html