function Animal(){ this.say = function(){ console.log("Hello"); }; } Animal.say();//Animal.say is not a function为什么这样无法访问 say 方法?var a = new Animal();a.say();//Hello而这样实例出来的却可以访问。如果要访问Animal.say却需要在函数外部写下面这个才能访问。Animal.say = function(){ console.log("Hello");};但是这样又会变成实例出来的不能访问了。需要变成:Animal.prototype.say = function(){ console.log("Hello"); };这样才能访问,但是这样Animal.say又不能访问。搞不清楚,头大,求解释。
添加回答
举报
0/150
提交
取消