I thought about another way to show Metaprogramming power and that's why I wrote a simple MetaDOM object.
What can You do with MetaDOM?
Nothing that You can't do with every JavaScript library, get elements, modify them ... but with this object You should use a sintax like this one:
with(MetaDOM){
While("p").Do(AddPNumber);
For("li").In("ul").Do(AddLiNumber);
If("div").class("some-div").Then(WriteSomeDiv);
If("*").class("paragraph").
Then(WriteSomeDiv).
ElseIf("*").id("paragraph").
Then(WriteSomeParagraphId)
;
With("body").Do(function(body){
body.innerHTML = 'MetaDOM Experiment
' + body.innerHTML;
});
If("*").name("h2").Then(AddH3);
};
Semmes cool? This is the example page, tested only with FireFox (and probably this alpha joke version works only with FireFox).
Do You understand better Metaprogramming and do you like it? :D
1 comment:
Nice stuff - the code is very literate. I hope to make some time to experiment with this approach.
Post a Comment