Hok's Macromedia Flash Blog

macromedia flash actionscript scripting, php, remoting, webservices, c#, javascript

Ads

Search

Avoiding-Bugs: Extension of built-in-prototypes

I have just thought about possible side-effects
that can occur if we use an prototype-extension
with the same name twice. Uhh, that could be
horrible especially for teamwork, so that everyone
have to know exactly what extensions the other
did.
A really simple solution is to check wether that
extension exist before we define the extension, if so
we can throw an error otherwise our trace-window
stay nice and clean...;-)
if (Object.prototype.addClass != undefined) {
   trace('ERROR: Object.prototype.addClass exist allready!');
}
Object.prototype.addClass = function (pConstructor) {
   // Adds a class to an object, to the
   // beginning of the proto-chain.
   var tmp = this.__proto__;
   this.__proto__ = pConstructor.prototype;
   this.__proto__.__proto__ = tmp;
}
ASSetPropFlags(Object.prototype, null, 1, 0);

So we can stay concentrate on the real importent
things in our programms.

The little philosophy behind this test is the self-testing-code
philosophy. That means that we only get a message if an
error happens and we did not have to evaluate trace window
for inconsistencies by our self.

Posted by hOk at April 29, 2003 03:12 PM

Comments (1)

Ugh, i have just seen that there is
an big failure in the addClass-Method.
The proto-cain of the class to add
will be cutted-off behind the first
proto. But now i am to pooped, for
wrestling with proto-chains...;-)
regards, Holger

Posted by hOk at April 30, 2003 03:46 AM


Name:


Email Address:


URL:


Comments:



You can use <code>code that should be highlightned</code> to highlight code!
Optionally you can use the attribut language="php|perl|java" within the code tag, otherwise
actionscript-highlightning will be used.

New Place