使用firebug时,它一直在声明this.speak没有定义,我不明白为什么这样,我正在尝试将其输出到屏幕上
$(document).ready (function() {
function person(rank, number, id) {
//properties
this.intRank = rank;
this.intNumber = number;
this.strId = id;
this.elOutput = document.getElementById(id);
//methods
this.speak = fucntion(); {
this.elOutput.innerHTML += "<br>" + this.strId;
};
//adds one to int number and speaks message
this.pickUpNumber = function() {
this.intNumber++;
this.strId = "i have" + this.intNumber.toString() + "rocks";
this.speak();
};
};
//object
var Jak = new person(5, "hey ,jack", " Captain");
var Cap = new person(3, "yea cap?", "jacko");
jak.speak(); cap.speak(); jak.pickUpRock();
});
this.speak = fucntion(); {
this.elOutput.innerHTML += "<br>" + this.strId;
};
我想你是说 function()
而且JS区分大小写。
可能这是您试图实现的目标:
$(document).ready (function() {
function person(rank, number, id) {
//properties
this.intRank = rank;
this.intNumber = number;
this.strId = id;
this.elOutput = document.getElementById(id);
//methods
this.speak = function() {
this.elOutput.innerHTML += "<br>" + this.strId;
};
//adds one to int number and speaks message
this.pickUpNumber = function() {
this.intNumber++;
this.strId = "i have" + this.intNumber.toString() + "rocks";
this.speak();
};
}
//object
var jak = new person(5, "hey ,jack", " Captain");
var cap = new person(3, "yea cap?", "jacko");
jak.speak(); cap.speak(); jak.pickUpNumber();
});
签出这个工作的jsbin
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句