function Animal(){ this.say = function(){ console.log("Hello"); }; } Animal.say();//Animal.say is not a function為什么這樣無(wú)法訪問(wèn) say 方法?var a = new Animal();a.say();//Hello而這樣實(shí)例出來(lái)的卻可以訪問(wèn)。如果要訪問(wèn)Animal.say卻需要在函數(shù)外部寫下面這個(gè)才能訪問(wèn)。Animal.say = function(){ console.log("Hello");};但是這樣又會(huì)變成實(shí)例出來(lái)的不能訪問(wèn)了。需要變成:Animal.prototype.say = function(){ console.log("Hello"); };這樣才能訪問(wèn),但是這樣Animal.say又不能訪問(wèn)。搞不清楚,頭大,求解釋。
關(guān)于 函數(shù)對(duì)象 方法的問(wèn)題?
哆啦的時(shí)光機(jī)
2019-02-13 14:57:44