You could assign a prototype object (*.prototype) another Object Literal ({}) but be careful for inheritage does not work properly anymore:
function Person() {}
Person.prototype.walk = function() { return 'I can walk' }
Person.prototype.swim = function() { return 'I can swim' }
function Man() {}
// select methods Man gets inherited here
// just assign certain methods from Person.prototype onto Man.prototype
// therefore Man.prototype inherites only walk method
Man.prototype = {
walk: Person.prototype.walk,
// so swim is not passed onto Man.prototype
// swim: Person.prototype.swim
};
var m = new Man();
// this throws an error
// because a object of type Man does not have got a swim method inherited
// m.swim(); Error!
console.log('is false: ', m instanceof Person);
console.log('parent constructor is Object: ', m.__proto__.__proto__.constructor);
But as you can see some checks to make sure what instance this object is and what super parent constructor it inherits some methods from do not work properly but they should work.
So you are better off by using inheritage in the right way:
function Person() {}
Person.prototype.walk = function() { return 'I can walk' }
Person.prototype.swim = function() { return 'I can swim' }
function Man() {}
Man.prototype = Object.create(Person.prototype);
var m = new Man();
// in this way Person gets every method that is assigned onto Person.prototype
// so swim method is available and can be used by objects of type Man now:
m.swim();
console.log('is true: ', m instanceof Person);
console.log('parent constructor is Person: ', m.__proto__.__proto__.constructor);
So that like instanceof operator and referenceing to a super parent constructor work properly. In this way all methods are assigned at once onto Person but by introducing additional abstract or parent constructors this might be avoidable.
Hope this helps.
swimmethod toAnimal? Your prototype is defined wrong.