Currently, I'm reading 'Object-Oriented JavaScript'. In addition, I've encountered a hiccup while carrying out an example from the book.
Below is the code sample:
var Dog = function() {
this.tail = true;
};
var benji = new Dog();
var rusty = new Dog();
Dog.prototype.say = function() { return "Woof!"; };
benji.say();
rusty.say();
Dog.prototype = {
paws: 4,
hair: true
};
Dog.prototype.constructor = Dog;
var lucy = new Dog();
lucy.say();
Essentially, the idea is to have the following work:
- console.log(lucy.say());
- console.log(benji.paws);
- The obvious - lucy.say();
etc.
Strangely enough, I've copied the example to the 'T', but to no avail. If anyone could shed some light I'd be more than grateful.
Cheers
lucy.constructor.prototype.pawsbut it won't givelucythesaymethod.