Helbrax said:
Hmm..how should I assign the methods? Like this?
critterObjcect.DrawAgent = doThis;
function doThis(args)
{
...
}
No, I was talking about the *identifier* instead:
critterObject.drawAgent = function()
{
// ...
};
Besides, on second thought, I don't understand your using this
hard-to-maintain `critterObject' reference instead of `this' *everywhere*.
And ISTM you are defining too many methods in the constructor where a
prototype method would have been better. Example:
function Foo(nBar)
{
if ((this.successful = !isNaN(nBar)))
{
this.bar = nBar;
}
}
Foo.prototype = {
constructor: Foo,
bar: 23,
baz: function()
{
window.alert(this.bar);
}
};
var foo = new Foo(42);
if (foo.successful)
{
foo.baz();
}
This loop will be going away, but why is it inefficient?
Because reqObj.length is evaluated in every loop.
Should I do:
for(...) if (...)
{
}
Certainly not, but:
for (var i = 0, len = somelength; i < len; i++)
In cases where order is not important (i.e. vice-versa iteration is OK),
for (var i = somelength; i--
suffices. We have discussed this here before.
I'll address this with the features in the constructor. If neither of
these is there, there is no sense in continuing, as the critter will
not display correctly.
Just in case you are unaware of that:
As you usually should not return a value from the constructor, there are
two possibilities for that: You throw an exception which makes your code
incompatible to JavaScript < 1.5, JScript < 5.0, ECMAScript < 3, see
http://PointedEars.de/scripts/es-matrix/
Or you define/test a property of the newly created object to
specify/determine that something when wrong during construction. See above.
Please include an empty line between quotation and new text next time.
PointedEars