@samitouri / QOS-React-2 / commits / 20af6b0a14

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.

Sebastian Markbage committed Oct 23, 2014 at 10:53 UTC 20af6b0a140c84f46d214cdc90a7c7aa9da1bf83
2 files changed +12 -2
src/core/ReactElement.js
+6 -2
@@ -120,12 +120,16 @@ var ReactElement = function(type, key, ref, owner, context, props) {
120 this.props = props;
121 };
122
123 +// We intentionally don't expose the function on the constructor property.
124 +// ReactElement should be indistinguishable from a plain object.
125 +ReactElement.prototype = {
126 + _isReactElement: true
127 +};
128 +
129 if (__DEV__) {
130 defineMutationMembrane(ReactElement.prototype);
131 }
132
127 -ReactElement.prototype._isReactElement = true;
128 -
133 ReactElement.createElement = function(type, config, children) {
134 var propName;
135
src/core/__tests__/ReactElement-test.js
+6
@@ -311,4 +311,10 @@ describe('ReactElement', function() {
311 expect(instance.getDOMNode().tagName).toBe('DIV');
312 });
313
314 + it('is indistinguishable from a plain object', function() {
315 + var element = React.createElement('div', { className: 'foo' });
316 + var object = {};
317 + expect(element.constructor).toBe(object.constructor);
318 + });
319 +
320 });