---
layout: page
title: "JavaScript runkit_class_emancipate function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/runkit_class_emancipate:821
- /functions/view/runkit_class_emancipate
- /functions/view/821
- /functions/runkit_class_emancipate:821
- /functions/821
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's runkit_class_emancipate

{% codeblock runkit/runkit_class_emancipate.js lang:js https://raw.github.com/kvz/phpjs/master/functions/runkit/runkit_class_emancipate.js raw on github %}
function runkit_class_emancipate (classname) {
  // http://kevin.vanzonneveld.net
  // +   original by: Brett Zamir (http://brett-zamir.me)
  // %          note 1: Function can only obtain classes from the global context
  // %          note 2: We have to delete all items on the prototype
  // *     example 1: function A () {}
  // *     example 1: A.prototype.methodA = function () {};
  // *     example 1: function B () {}
  // *     example 1: runkit_class_adopt('B', 'A');
  // *     example 1: runkit_class_emancipate('B');
  // *     returns 1: true

  if (typeof this.window[classname] !== 'function') {
    return false;
  }

  for (var p in this.window[classname].prototype) {
    delete this.window[classname].prototype[p];
  }
  return true;
}
{% endcodeblock %}

 - [view on github](https://github.com/kvz/phpjs/blob/master/functions/runkit/runkit_class_emancipate.js)
 - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/runkit/runkit_class_emancipate.js)

### Example 1
This code
{% codeblock lang:js example %}
function A () {}
A.prototype.methodA = function () {};
function B () {}
runkit_class_adopt('B', 'A');
runkit_class_emancipate('B');
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}


### Other PHP functions in the runkit extension
{% render_partial _includes/custom/runkit.html %}
