Hide ReactElement constructor

This prevents feature tests like:

var ReactElement = React.createElement(...).constructor;

if (element.constructor === ReactElement)

This is intentional so that we have the option to make these plain objects.
E.g. for direct inlining or replacing them with value types.
This commit is contained in:
Sebastian Markbage
2014-10-23 12:08:14 -07:00
parent 8de03c47dd
commit 7ce8c844bd
2 changed files with 12 additions and 2 deletions
+6 -2
View File
@@ -120,12 +120,16 @@ var ReactElement = function(type, key, ref, owner, context, props) {
this.props = props;
};
// We intentionally don't expose the function on the constructor property.
// ReactElement should be indistinguishable from a plain object.
ReactElement.prototype = {
_isReactElement: true
};
if (__DEV__) {
defineMutationMembrane(ReactElement.prototype);
}
ReactElement.prototype._isReactElement = true;
ReactElement.createElement = function(type, config, children) {
var propName;
+6
View File
@@ -402,4 +402,10 @@ describe('ReactElement', function() {
expect(instance.getDOMNode().tagName).toBe('DIV');
});
it('is indistinguishable from a plain object', function() {
var element = React.createElement('div', { className: 'foo' });
var object = {};
expect(element.constructor).toBe(object.constructor);
});
});