Серожа (ckayt) wrote,
Серожа
ckayt

javascript lambda functions, javascript analog of php.net/create_function

function create_function(args, body){
eval('var f = (function('+args+'){'+body+'});');
return f;
};

//

var a = ['be','me'];
var f = [];

for(var i in a)
f[i] = create_function('', 'return a['+i+'];');
//eval('f['+i+'] = (function(){ return a['+i+']; });');

for(var i in f)
alert(f[i]+' = '+f[i]());
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

  • 0 comments