function Tt(){ this.name = "hello"; this.age = 88; if(typeof this.say != "function"){ Tt.prototype = { constructor: Tt, say: function(){ return this.name; } }; }}var t = new Tt();**console.log(t.say()); // Uncaught TypeError: Object #<Tt> has no method 'say' 这里为什么访问不到方法???**// 如果这么做function Tt(){ this.name = "hello"; this.age = 88; if(typeof this.say != "function"){ Tt.prototype.say = function(){ return this.name; } }}var t = new Tt();**console.log(t.say()); // 这样就没有问题!**
添加回答
举报
0/150
提交
取消