Javascript create_function : Function Handling : PHP functions in JavaScript JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » PHP functions in JavaScript » Function Handling »

 

Javascript create_function


Creates an anonymous function, and returns its name
Example 1

Running
1.f = create_function('a, b', "return (a + b);");
2.f(1, 2);

Could return
1.3
function create_function (args, code) {
    // Creates an anonymous function, and returns its name (funny, eh?)  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/create_function
    // +   original by: Johnny Mast (http://www.phpvrouwen.nl)
    // *     example 1: f = create_function('a, b', "return (a + b);");
    // *     example 1: f(1, 2);
    // *     returns 1: 3
    
    eval('var _oFunctionObject = function (' + args + ') { ' +  code + '}');
    return _oFunctionObject;
}


HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo PHP functions in JavaScript
» Function Handling