36
rated 0 times
[
43]
[
7]
/ answers: 1 / hits: 32708
/ 15 Years ago, wed, february 25, 2009, 12:00:00
I'm wondering if there's a better way to add dynamic methods to an existing object. Basically, I am trying to assemble new methods dynamically and then append them to an existing function.
This demo code works.
builder = function(fn, methods){
//method builder
for(p in methods){
method = 'fn.' + p + '=' + methods[p];
eval(method);
}
return fn;
}
test = {}
test = builder(test, {'one':'function(){ alert(one); }','two':'function(){ alert(two); }'} );
test.one();
test.two();
More From » dynamic