Серожа (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]());
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments