View Full Version : At the core of an object

06-09-2007, 01:25 AM
The other day i ran into a case where i had an object with almost all its methods executing the same check at start.

Which led me to wonder if there is any high level method that runs no matter what lower level method is called, where i could implement this check???

06-09-2007, 02:01 AM
not quite sure what you are talking about.... could you provide an example of what you are talking about, and maybe a little more explaination?

06-09-2007, 02:47 AM
ok, let's take a very basic example to illustrate what im trying to do:

pretend i have a object of class Dog with the following function "bark", "run", "eat". In every of these methods, i have a check that basically does:

if(sleeping) return

what i want to do, is pre-register at initialization level the methods subject to this check and call another method (wake up) if (asleep),
rather than having the same check within each function

06-09-2007, 10:38 AM
what you're talking about is called Aspect Oriented Programming, and there are a few ways of doing this with javascript. http://beppu.lbox.org/articles/2006/09/06/actsasaspect is one I've used in the past.

06-09-2007, 05:20 PM
very nice little piece of code.
I am going to dig into the whole Aspect Oriented Programming concept, this seems to be only the tip of a powerful iceberg. thanks!!