我正在通过了解如何创建具有属性和方法的构造函数来工作。我已经编写并测试了下面的一个,但它不起作用。有人可以花时间帮助我了解是什么导致这不起作用。了解我已经搜索过谷歌,我正在阅读书籍等,但需要一些帮助来理解这个概念并创建我自己的。谢谢你。
function ball( type, grip, shape ) {
this.type = type;
this.grip = grip;
this.shape = shape;
this.caught = function( who,how ) {
this.who = who;
this.how = how;
};
this.player = function() {
return (who + "caught the ball" + how + "that was a" + type + "shaped like
a " + shape + "thrown with a" + grip);
};
};
var baseball = new ball("Mickey Mantle","sliding","baseball","circle","fastball");
console.log(ball);
编辑: 从下面的答案中-感谢您的分享-我已经创建了我的 jsfiddle,但无法理解为什么被捕获的属性不起作用。我应该如何设置此方法的属性?