0
我有一個構造函數「動物」,即命名空間一些其他的構造函數,「鱷魚」和「西遊記」:原型命名空間
var Monkey = function(Animals) {
this.Animals = Animals;
};
Monkey.prototype.feedMe = function() {
this.Animals.feed();
};
var Crocodile = function(Animals) {
this.Animals = Animals;
};
Crocodile.prototype.feedMe = function() {
this.Animals.feed();
};
var Animals = function(zoo) {
this.zoo = zoo;
};
Animals.prototype.feed = function() {
//feed the animal
};
Animals.prototype.Monkey = function() {
this.Animals = Animals.prototype;
};
Animals.prototype.Monkey.prototype = Monkey.prototype;
Animals.prototype.Crocodile = function() {
this.Animals = Animals.prototype;
};
Animals.prototype.Crocodile.prototype = Crocodile.prototype;
的意圖,我應該能夠做到以下幾點:
var animals = new Animals("NY");
var monkey = new animals.Monkey();
monkey.feed();
我收到一個錯誤,指出monkey.feed()不是函數。我假設我做了錯誤的方式,我繼承了動物構造函數中的猴子函數,但對於我的生活,我一直無法找到解決方案。
什麼是我應該使用命名空間這些功能的正確方法?
'Animals.prototype.feed(){// 餵動物 };'ISN」一個函數 - 你省略了'function'關鍵字。 – Graham 2012-07-06 09:04:08
對不起,當我複製代碼時,這是一個疏忽。糾正。 – 2012-07-06 09:07:21