关于作者

Discuss / JavaScript / JS创建对象练习题的问题

JS创建对象练习题的问题

情深不寿553

#1 Created at ...

'use strict';

function Cat(name){ this.name = name; } Cat.prototype.say = function(){ console.log('Hello, Kitty!'); };

var kitty = new Cat('Kitty'); var doraemon = new Cat('哆啦A梦'); if (kitty && kitty.name === 'Kitty' && kitty.say && typeof kitty.say === 'function' && kitty.say() === 'Hello, Kitty!' && kitty.say === doraemon.say) { console.log('测试通过!'); } else { console.log(kitty.say+","+doraemon.say); } 为什么我用了prototype 但是哆啦A梦和kitty 调用say方法依旧是不一样的

情深不寿553

#2 Created at ...

已经解决了 不是这个问题 我弄错了


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.