trying to run a constructor function via loop, getting error
I'm just now learning about, and experimenting with JS's OOP capabilities.
in the code below i'm trying to run a constructor function inside a loop but am getting the following error via Firebug
I've put in the error in comments where it occurs. how can i fix this?,
thanks everyone, have a great weeked.
PHP Code:
function cat(name) {
this.name = name;
this.talk = function() {
alert(this.name + " say meeow!")
}
}
/* THESE WORK PROPERLY
cat1 = new cat("felix")
cat1.talk()
*/
var manyCats = ['George', 'Tom', 'Josh', 'Remy', 'Jeff']
for(i=0;i<manyCats.length;i++) {
cat+i = new cat(manyCats[i]); //ERROR INVALID ASSIGNMENT LEF-THAND SIDE
//should create cat0 = new cat("George");
}
What this statement is saying, is take the function cat, add the value of 'i' to it (not possible), then make it equal an object (of which that same function creates)... I think you can see why it didn't work that way. That's why it was changed to a "pussy" array,,, lmao.. I got a laugh out of this tho, thanks.
why does text disappear in the text box when i click the convert button in my temperature converter program...it appears for a sec and the disappears. how can the result be fixed??? thanx...
Bookmarks