目前,我正在阅读"面向对象的JavaScript".另外,我从书中拿出一个例子时遇到了打嗝.
以下是代码示例:
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();
Run Code Online (Sandbox Code Playgroud)
基本上,这个想法是要做以下工作:
等等
奇怪的是,我已经将示例复制到'T',但无济于事.如果有人能说出一些亮点,我会感激不尽.
干杯
javascript ×1