作者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/cn.aspx?n=bbs/Ajax/M.1450957569.A.0F0.html