@samitouri / QOS-React-2 / commits / 7ce8c844bd

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 7ce8c844bda7d2fe204ad59c10092ffde3f53938
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
@@ -402,4 +402,10 @@ describe('ReactElement', function() {
402 expect(instance.getDOMNode().tagName).toBe('DIV');
403 });
404
405 + it('is indistinguishable from a plain object', function() {
406 + var element = React.createElement('div', { className: 'foo' });
407 + var object = {};
408 + expect(element.constructor).toBe(object.constructor);
409 + });
410 +
411 });