phpjs
Version:
52 lines (45 loc) • 1.75 kB
Markdown
layout: page
title: "JavaScript runkit_function_rename function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/runkit_function_rename:826
- /functions/view/runkit_function_rename
- /functions/view/826
- /functions/runkit_function_rename:826
- /functions/826
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's runkit_function_rename
{% codeblock runkit/runkit_function_rename.js lang:js https://raw.github.com/kvz/phpjs/master/functions/runkit/runkit_function_rename.js raw on github %}
function runkit_function_rename (funcname, newname) {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brett-zamir.me)
// % note 1: Function can only be copied to and from the global context
// * example 1: function plus (a, b) { return (a + b); }
// * example 1: runkit_function_rename('plus', 'add');
// * returns 1: true
if (typeof this.window[newname] !== 'function' || this.window[funcname] !== undefined) { // (presumably disallow overwriting existing variables)
return false;
}
this.window[newname] = this.window[funcname];
this.window[funcname] = undefined;
return true;
}
{% endcodeblock %}
- [view on github](https://github.com/kvz/phpjs/blob/master/functions/runkit/runkit_function_rename.js)
- [edit on github](https://github.com/kvz/phpjs/edit/master/functions/runkit/runkit_function_rename.js)
### Example 1
This code
{% codeblock lang:js example %}
function plus (a, b) { return (a + b); }
runkit_function_rename('plus', 'add');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}
### Other PHP functions in the runkit extension
{% render_partial _includes/custom/runkit.html %}