Phrogz wrote:
> What I would like is a forEach type method where the 'this' scope used
> inside the callback is the same as the 'this' scope that was used to
> invoke the forEach. For example:
>
> G = {}
> G.a = this;
> myArray.each( function(){ G.b = this } );
>
> I would like G.a===G.b
I'm not using prototype for such tricky things, and sure you are not
doing it to alert cats' names

so depending on the real purpose it
can be not suitable. But withing the spelled requirements I would do it
this way (keeping all methods as static):
<html>
<head>
<title>Cats</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function Person(inName, inCats) {
this.name = inName;
this.cats = inCats;
this.cats.each = each;
this.cats.context = this;
this.showCats = Person.showCats;
}
Person.showCats = function() {
this.cats.each(alertCat);
}
function each(fnCallBack) {
for (var i=0; i<this.length; i++) {
fnCallBack.call(this.context, this[i]);
}
}
function alertCat(catName) {
window.alert(this.name + ' has ' + catName);
}
phrogz = new Person('Gavin', ['Fuzzles', 'Kitty']);
phrogz.showCats();
</script>
</head>
<body>
</body>
</html>