JavaScript runkit_function_add function

A JavaScript equivalent of PHP’s runkit_function_add
function runkit_function_add (funcname, arglist, code) {
  // http://kevin.vanzonneveld.net
  // +   original by: Brett Zamir (http://brett-zamir.me)
  // %          note 1: Function can only be added to the global context; use create_function() for an anonymous function
  // *     example 1: runkit_function_add('add', 'a, b', "return (a + b);");
  // *     returns 1: true
  if (this.window[funcname] !== undefined) { // Presumably disallows adding where exists, since there is also redefine function
    return false;
  }

  try {
    this.window[funcname] = Function.apply(null, arglist.split(',').concat(code));
  } catch (e) {
    return false;
  }
  return true;
}

Example 1
runkit_function_add('add', 'a, b', "return (a + b);");

Should return
true
Теги:
runkit_function_add
Добавлено: 27 Июля 2018 20:20:48 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...