I do not think that something is wrong with this. The syntax is a bit funky, but it's a smart trick.
I would question the need for a truly private variable. I can only think of two reasons why someone might want them, but both can be debunked.
1) You make a library for others to consume ... If someone picks inside your library code where they shouldn't be, they either violate their own experience or work with errors that they found in your code. In any case, no harm to you or others. Worse, they violate their own application. Private variables left a very bad taste in the mouth coming from Flex. Open JavaScript is a breath of fresh air IMO.
2) You want to hide personal data inside your application ... With modern browsers, anything in JavaScript can be checked and changed at runtime. Unable to hide data from users in JavaScript. You can only complicate the search.
I know that this alternative is not really private, but the use is the same. Since I am not a big fan of the struggle to make something private, I’ll turn it on anyway .; D)
var Hello = React.createClass({ name: null, getInitialState: function() { this.name = "Sir " + this.props.name; return null; }, render: function() { return <div>Hello {this.name}</div>; }; }); React.render(<Hello name="World" />, document.getElementById('container'));
source share