Moving from `prototype` and `new` to a closure-and-exposure pattern
问题 I have been re-factoring someone else's JavaScript code. BEFORE: function SomeObj(flag) { var _private = true; this.flag = (flag) ? true : false; this.version="1.1 (prototype)"; if (!this._someProperty) this._init(); // leading underscore hints at what should be a 'private' to me this.reset(); // assumes reset has been added... } SomeObj.prototype.reset = function() { /* perform some actions */ } /* UPDATE */ SomeObj.prototype.getPrivate = function() { return _private; // will return