mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user