Sure, here is it:
https://github.com/nodirt/defineClass
=========
Here are some AOP features I plan to add by the weekend:
1. A trait can import/implement other traits. Scala supports that.
It's gonna look like this:
var trait1 = defineClass.trat({
m: function () { ... }
});
var trait2 = defineClass.trait({
_super: trait1 //
m2: function () { ... }
});
Here trait2 includes trait1 implementation. It can override existing
methods and call them as this._super(..).
trait1, trait2 themselves are functions that receive a class/prototype
and return a class/prototype with the trait applied.
2. Python-like class/function decorators. Apply behavior after class
is composed:
// define a decorator. This one will log exceptions
var logException = defineClass.decorator(function () {
try {
// call the method that is being decorated
return this._super();
}
catch (err) {
console.log(err);
throw;
}
});
// apply the decorator to a method
var Bar = defineClass({
// let me reserve the $ for this
$baz: logException,
baz: function (x) {
return 1/x;
}
});
// apply the decorator to all methods:
var Foo = defineClass({
$: logException,
m: function (x) {
return 1/x;
}
});
A chain decorators can be applied to a class/method.
In fact, the logException is just a function that receives and returns
a class/method/prototype. defineClass just applies it uses the return
value.
As I wrote above, trait1 is a function too, so it can be used as decorator too.
-Nodir
On Wed, May 23, 2012 at 7:28 PM, alessioalex <[email protected]> wrote:
> Yes true, the purpose of Cls is to simulate plain old class inheritance,
> nothing more. I'm not sure of what module you're talking about with
> defineClass. Can you provide a link so I can checkout the implementation?
>
> Thanks,
> - Alex
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en