var Animal = { createNew: function () { var animal = {}; animal.makeSound = function () { console.log("o(∩_∩)o"); }; return animal; }, };
var Cat = { sound: "喵喵", createNew: function () { var cat = Animal.createNew(); // var sound = '喵喵' cat.name = "mm"; cat.makeSound = function () { console.log(Cat.sound); }; cat.changeSound = function (sound) { Cat.sound = sound; }; return cat; }, };
var cat = Cat.createNew(); var cat2 = Cat.createNew(); cat.changeSound("呜呜"); console.log(cat.sound); // undefined cat.makeSound(); // 呜呜 cat2.makeSound(); // 呜呜 // console.log(cat instanceof Cat) // Right-hand side of 'instanceof' is not callable